|
|
|
|
@ -1,10 +1,10 @@
|
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
|
|
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/config/config.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/config/size_config.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/core/model/get_medication_response_model.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/core/viewModel/medicine_view_model.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/screens/base/base_view.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/screens/medicine/pharmacies_list_screen.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
|
|
|
|
|
@ -12,13 +12,13 @@ import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/util/helpers.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/widgets/medicine/medicine_item_widget.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/widgets/shared/Text.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/loader/gif_loader_dialog_utils.dart';
|
|
|
|
|
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:hexcolor/hexcolor.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:speech_to_text/speech_recognition_error.dart';
|
|
|
|
|
import 'package:speech_to_text/speech_recognition_result.dart';
|
|
|
|
|
@ -117,151 +117,169 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return BaseView<MedicineViewModel>(
|
|
|
|
|
onModelReady: (model) async {
|
|
|
|
|
if (model.allMedicationList.length == 0)
|
|
|
|
|
await model.getMedicationList();
|
|
|
|
|
// if (model.allMedicationList.length == 0)
|
|
|
|
|
// await model.getMedicationList();
|
|
|
|
|
},
|
|
|
|
|
builder: (_, model, w) => AppScaffold(
|
|
|
|
|
baseViewModel: model,
|
|
|
|
|
isShowAppBar: false,
|
|
|
|
|
appBarTitle: TranslationBase.of(context).searchMedicine,
|
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
|
child: FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.97,
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Container(
|
|
|
|
|
// height: SizeConfig.screenHeight,
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: SizeConfig.screenHeight * .16,
|
|
|
|
|
),
|
|
|
|
|
Column(children: [
|
|
|
|
|
FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.9,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
// height: MediaQuery.of(context).size.height * 0.070,
|
|
|
|
|
child: InkWell(
|
|
|
|
|
onTap: model.allMedicationList != null
|
|
|
|
|
? () {
|
|
|
|
|
setState(() {
|
|
|
|
|
_selectedMedication = null;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
: null,
|
|
|
|
|
child: _selectedMedication == null
|
|
|
|
|
? AutoCompleteTextField<
|
|
|
|
|
GetMedicationResponseModel>(
|
|
|
|
|
decoration: textFieldSelectorDecoration(
|
|
|
|
|
TranslationBase.of(context)
|
|
|
|
|
.searchMedicineNameHere,
|
|
|
|
|
_selectedMedication != null
|
|
|
|
|
? _selectedMedication.genericName
|
|
|
|
|
: null,
|
|
|
|
|
true,
|
|
|
|
|
icon: EvaIcons.search),
|
|
|
|
|
itemSubmitted: (item) => setState(
|
|
|
|
|
() => _selectedMedication = item),
|
|
|
|
|
key: key,
|
|
|
|
|
suggestions: model.allMedicationList,
|
|
|
|
|
itemBuilder: (context, suggestion) =>
|
|
|
|
|
new Padding(
|
|
|
|
|
child: Texts(
|
|
|
|
|
suggestion.description +
|
|
|
|
|
'/' +
|
|
|
|
|
suggestion.genericName),
|
|
|
|
|
padding: EdgeInsets.all(10.0)),
|
|
|
|
|
itemSorter: (a, b) => 1,
|
|
|
|
|
itemFilter: (suggestion, input) =>
|
|
|
|
|
suggestion.genericName
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.startsWith(
|
|
|
|
|
input.toLowerCase()) ||
|
|
|
|
|
suggestion.description
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.startsWith(
|
|
|
|
|
input.toLowerCase()) ||
|
|
|
|
|
suggestion.keywords
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.startsWith(input.toLowerCase()),
|
|
|
|
|
)
|
|
|
|
|
: TextField(
|
|
|
|
|
minLines: 2,
|
|
|
|
|
maxLines: 2,
|
|
|
|
|
decoration: textFieldSelectorDecoration(
|
|
|
|
|
TranslationBase.of(context)
|
|
|
|
|
.searchMedicineNameHere,
|
|
|
|
|
_selectedMedication != null
|
|
|
|
|
? _selectedMedication
|
|
|
|
|
.description +
|
|
|
|
|
(' (${_selectedMedication.genericName} )')
|
|
|
|
|
: null,
|
|
|
|
|
true,
|
|
|
|
|
icon: EvaIcons.search),
|
|
|
|
|
enabled: false,
|
|
|
|
|
),
|
|
|
|
|
builder: (_, model, w) {
|
|
|
|
|
myController.text =model.searchText;
|
|
|
|
|
return AppScaffold(
|
|
|
|
|
// baseViewModel: model,
|
|
|
|
|
isShowAppBar: false,
|
|
|
|
|
appBarTitle: TranslationBase.of(context).searchMedicine,
|
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
|
child: FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.97,
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Container(
|
|
|
|
|
// height: SizeConfig.screenHeight,
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: SizeConfig.screenHeight * .16,
|
|
|
|
|
),
|
|
|
|
|
FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.9,
|
|
|
|
|
child: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius:
|
|
|
|
|
BorderRadius.all(Radius.circular(6.0)),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
width: 1.0, color: HexColor("#CCCCCC"))),
|
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
|
child: AppTextFormField(
|
|
|
|
|
borderColor: Colors.white,
|
|
|
|
|
hintText: TranslationBase.of(context)
|
|
|
|
|
.searchMedicineNameHere,
|
|
|
|
|
controller: myController,
|
|
|
|
|
onSaved: (value) {},
|
|
|
|
|
onFieldSubmitted: (value) {
|
|
|
|
|
searchMedicine(context, model);
|
|
|
|
|
},
|
|
|
|
|
inputFormatter: ONLY_LETTERS,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
]),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: SizeConfig.screenHeight * .5,
|
|
|
|
|
),
|
|
|
|
|
Column(
|
|
|
|
|
children: [
|
|
|
|
|
FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.97,
|
|
|
|
|
child: Wrap(
|
|
|
|
|
alignment: WrapAlignment.center,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
// TODO change it secondary button and add loading
|
|
|
|
|
AppButton(
|
|
|
|
|
title: TranslationBase.of(context).search,
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
await searchMedicine(context, model);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.9,
|
|
|
|
|
child: Container(
|
|
|
|
|
child: Wrap(
|
|
|
|
|
alignment: WrapAlignment.center,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
// TODO change it secondary button and add loading
|
|
|
|
|
AppButton(
|
|
|
|
|
title: TranslationBase.of(context).search,
|
|
|
|
|
onPressed: () async{
|
|
|
|
|
await searchMedicine(context, model);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
Container(
|
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
|
left: SizeConfig.heightMultiplier * 2),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
AppText(
|
|
|
|
|
TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.youCanFind +
|
|
|
|
|
(myController.text !=''?model.pharmacyItemsList.length
|
|
|
|
|
.toString():'0' )+
|
|
|
|
|
" " +
|
|
|
|
|
TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.itemsInSearch,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height:10,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)),
|
|
|
|
|
if(myController.text !='')
|
|
|
|
|
Container(
|
|
|
|
|
height: MediaQuery
|
|
|
|
|
.of(context)
|
|
|
|
|
.size
|
|
|
|
|
.height * 0.5,
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
padding: const EdgeInsets.only(top:20),
|
|
|
|
|
|
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
|
// shrinkWrap: true,
|
|
|
|
|
itemCount:
|
|
|
|
|
model.pharmacyItemsList ==
|
|
|
|
|
null
|
|
|
|
|
? 0
|
|
|
|
|
: model
|
|
|
|
|
.pharmacyItemsList.length,
|
|
|
|
|
itemBuilder:
|
|
|
|
|
(BuildContext context, int index) {
|
|
|
|
|
return InkWell(
|
|
|
|
|
child: MedicineItemWidget(
|
|
|
|
|
label: model
|
|
|
|
|
.pharmacyItemsList[index]
|
|
|
|
|
["ItemDescription"],
|
|
|
|
|
url: model
|
|
|
|
|
.pharmacyItemsList[index]
|
|
|
|
|
["ImageSRCUrl"],
|
|
|
|
|
),
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) =>
|
|
|
|
|
PharmaciesListScreen(
|
|
|
|
|
itemID: model
|
|
|
|
|
.pharmacyItemsList[
|
|
|
|
|
index]["ItemID"],
|
|
|
|
|
url: model
|
|
|
|
|
.pharmacyItemsList[
|
|
|
|
|
index]["ImageSRCUrl"]),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);}
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchMedicine(context, MedicineViewModel model) async {
|
|
|
|
|
FocusScope.of(context).unfocus();
|
|
|
|
|
if (_selectedMedication.isNullOrEmpty()) {
|
|
|
|
|
helpers.showErrorToast(TranslationBase.of(context).typeMedicineName);
|
|
|
|
|
if (myController.text.isNullOrEmpty()) {
|
|
|
|
|
helpers.showErrorToast(TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.typeMedicineName);
|
|
|
|
|
//"Type Medicine Name")
|
|
|
|
|
return;
|
|
|
|
|
} else if (_selectedMedication.description.length < 3) {
|
|
|
|
|
helpers.showErrorToast(TranslationBase.of(context).moreThan3Letter);
|
|
|
|
|
}
|
|
|
|
|
if (myController.text.length < 3) {
|
|
|
|
|
helpers.showErrorToast(TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.moreThan3Letter);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => PharmaciesListScreen(
|
|
|
|
|
itemID: _selectedMedication.itemId,
|
|
|
|
|
selectedMedication: _selectedMedication,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
// await model.getMedicineItem(_selectedMedication.description);
|
|
|
|
|
// GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
|
|
|
|
|
await model.getMedicineItem(myController.text);
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startVoiceSearch() {
|
|
|
|
|
|