You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
5.6 KiB
Dart
156 lines
5.6 KiB
Dart
import 'package:doctor_app_flutter/config/config.dart';
|
|
import 'package:doctor_app_flutter/config/size_config.dart';
|
|
import 'package:doctor_app_flutter/providers/medicine_provider.dart';
|
|
import 'package:doctor_app_flutter/screens/medicine/pharmacies_list_screen.dart';
|
|
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
|
|
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
|
|
import 'package:doctor_app_flutter/util/helpers.dart';
|
|
import 'package:doctor_app_flutter/widgets/medicine/medicine_item_widget.dart';
|
|
import 'package:doctor_app_flutter/widgets/shared/app_buttons_widget.dart';
|
|
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
|
|
import 'package:doctor_app_flutter/widgets/shared/app_text_form_field.dart';
|
|
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
|
|
import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../../util/extenstions.dart';
|
|
|
|
DrAppSharedPreferances sharedPref = DrAppSharedPreferances();
|
|
|
|
class MedicineSearchScreen extends StatefulWidget with DrAppToastMsg {
|
|
MedicineSearchScreen({this.changeLoadingStata});
|
|
final Function changeLoadingStata;
|
|
|
|
@override
|
|
_MedicineSearchState createState() => _MedicineSearchState();
|
|
}
|
|
|
|
class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
var data;
|
|
final myController = TextEditingController();
|
|
Helpers helpers = new Helpers();
|
|
|
|
MedicineProvider _medicineProvider;
|
|
|
|
bool _isInit = true;
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
if (_isInit) {
|
|
_medicineProvider = Provider.of<MedicineProvider>(context);
|
|
}
|
|
_isInit = false;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
return AppScaffold(
|
|
appBarTitle: "Search Medicine",
|
|
body: Column(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: EdgeInsets.only(
|
|
bottom: SizeConfig.heightMultiplier * 1,
|
|
right: SizeConfig.heightMultiplier * 2,
|
|
left: SizeConfig.heightMultiplier * 2,
|
|
top: SizeConfig.heightMultiplier * 3),
|
|
child: AppTextFormField(
|
|
hintText: 'Search Medicine Name Here..',
|
|
controller: myController,
|
|
onSaved: (value) {},
|
|
inputFormatter: ONLY_LETTERS),
|
|
),
|
|
|
|
Container(
|
|
margin: EdgeInsets.only(bottom: 5,
|
|
left: 10,
|
|
right: 10,
|
|
top: 0),
|
|
child: Wrap(
|
|
alignment: WrapAlignment.center,
|
|
children: <Widget>[
|
|
AppButton(
|
|
title: "Search",
|
|
color: Color(PRIMARY_COLOR),
|
|
onPressed: () {
|
|
searchMedicine(context);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: SizeConfig.heightMultiplier * 2),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
AppText(
|
|
"You find " + (data == null ? "0": data.length.toString())+" items in search",
|
|
fontWeight: FontWeight.bold,
|
|
margin: 5,),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Container(
|
|
width: SizeConfig.screenWidth * 0.97,
|
|
child: !_medicineProvider.isFinished
|
|
? DrAppCircularProgressIndeicator()
|
|
: _medicineProvider.hasError
|
|
? Center(
|
|
child: Text(
|
|
_medicineProvider.errorMsg,
|
|
style: TextStyle(
|
|
color: Theme.of(context).errorColor),
|
|
),
|
|
):ListView.builder(
|
|
scrollDirection: Axis.vertical,
|
|
shrinkWrap: true,
|
|
itemCount: data == null ? 0 : data.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
return InkWell(
|
|
child: MedicineItemWidget(
|
|
label: data[index]["ItemDescription"],
|
|
url: data[index]["ProductImageBase64"],
|
|
),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => ChangeNotifierProvider(
|
|
create: (_) => MedicineProvider(),
|
|
child: PharmaciesListScreen(
|
|
itemID: data[index]["ItemID"], url: data[index]["ProductImageBase64"]),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
));
|
|
}
|
|
|
|
searchMedicine(context) {
|
|
FocusScope.of(context).unfocus();
|
|
if (myController.text.isNullOrEmpty()) {
|
|
this.setState(() {
|
|
data = null;
|
|
});
|
|
helpers.showErrorToast("Type Medicine Name");
|
|
return;
|
|
}
|
|
_medicineProvider.getMedicineItem(myController.text).then((str) {
|
|
this.setState(() {
|
|
data = _medicineProvider.pharmacyItemsList;
|
|
});
|
|
});
|
|
}
|
|
}
|