|
|
|
|
@ -1,7 +1,8 @@
|
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
|
|
import 'package:doctor_app_flutter/config/config.dart';
|
|
|
|
|
import 'package:autocomplete_textfield/autocomplete_textfield.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';
|
|
|
|
|
@ -11,12 +12,12 @@ 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:doctor_app_flutter/widgets/shared/network_base_view.dart';
|
|
|
|
|
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:speech_to_text/speech_recognition_error.dart';
|
|
|
|
|
@ -45,6 +46,9 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
|
|
|
bool _isInit = true;
|
|
|
|
|
final SpeechToText speech = SpeechToText();
|
|
|
|
|
String lastStatus = '';
|
|
|
|
|
GetMedicationResponseModel _selectedMedication;
|
|
|
|
|
GlobalKey key =
|
|
|
|
|
new GlobalKey<AutoCompleteTextFieldState<GetMedicationResponseModel>>();
|
|
|
|
|
|
|
|
|
|
// String lastWords;
|
|
|
|
|
List<LocaleName> _localeNames = [];
|
|
|
|
|
@ -84,142 +88,206 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InputDecoration textFieldSelectorDecoration(String hintText,
|
|
|
|
|
String selectedText, bool isDropDown,
|
|
|
|
|
{IconData icon}) {
|
|
|
|
|
return InputDecoration(
|
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: Color(0xFFCCCCCC), width: 2.0),
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: Color(0xFFCCCCCC), width: 2.0),
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
disabledBorder: OutlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: Color(0xFFCCCCCC), width: 2.0),
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
hintText: selectedText != null ? selectedText : hintText,
|
|
|
|
|
suffixIcon: isDropDown ? Icon(icon ?? Icons.arrow_drop_down) : null,
|
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
color: Colors.grey.shade600,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return BaseView<MedicineViewModel>(
|
|
|
|
|
builder: (_, model, w) => AppScaffold(
|
|
|
|
|
appBarTitle: TranslationBase.of(context).searchMedicine,
|
|
|
|
|
body: FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.97,
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
child: Icon(
|
|
|
|
|
DoctorApp.medicine_search,
|
|
|
|
|
size: 100,
|
|
|
|
|
color: Colors.black,
|
|
|
|
|
),
|
|
|
|
|
margin: EdgeInsets.only(top: 50),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 12.0),
|
|
|
|
|
child: AppText(
|
|
|
|
|
TranslationBase.of(context).type.toUpperCase(),
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: SizeConfig.heightMultiplier * 2.5,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 5.0),
|
|
|
|
|
child: AppText(
|
|
|
|
|
TranslationBase.of(context).searchMedicineImageCaption,
|
|
|
|
|
fontSize: SizeConfig.heightMultiplier * 2,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 15,
|
|
|
|
|
),
|
|
|
|
|
FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.9,
|
|
|
|
|
onModelReady: (model) async {
|
|
|
|
|
if(model.allMedicationList.isNotEmpty)
|
|
|
|
|
await model.getMedicationList();
|
|
|
|
|
},
|
|
|
|
|
builder: (_, model, w) =>
|
|
|
|
|
AppScaffold(
|
|
|
|
|
baseViewModel: model,
|
|
|
|
|
appBarTitle: TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.searchMedicine,
|
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
|
child: FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.97,
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
child: AppTextFormField(
|
|
|
|
|
hintText: TranslationBase.of(context)
|
|
|
|
|
.searchMedicineNameHere,
|
|
|
|
|
controller: myController,
|
|
|
|
|
onSaved: (value) {},
|
|
|
|
|
onFieldSubmitted: (value) {
|
|
|
|
|
searchMedicine(context, model);
|
|
|
|
|
},
|
|
|
|
|
textInputAction: TextInputAction.search,
|
|
|
|
|
// TODO return it back when it needed
|
|
|
|
|
// prefix: IconButton(
|
|
|
|
|
// icon: Icon(Icons.mic),
|
|
|
|
|
// color:
|
|
|
|
|
// lastStatus == 'listening' ? Colors.red : Colors.grey,
|
|
|
|
|
// onPressed: () {
|
|
|
|
|
// myController.text = '';
|
|
|
|
|
// setState(() {
|
|
|
|
|
// lastStatus = 'listening';
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// startVoiceSearch();
|
|
|
|
|
// }),
|
|
|
|
|
inputFormatter: ONLY_LETTERS),
|
|
|
|
|
Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
child: Icon(
|
|
|
|
|
DoctorApp.medicine_search,
|
|
|
|
|
size: 100,
|
|
|
|
|
color: Colors.black,
|
|
|
|
|
),
|
|
|
|
|
margin: EdgeInsets.only(top: 50),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 12.0),
|
|
|
|
|
child: AppText(
|
|
|
|
|
TranslationBase.of(context).type.toUpperCase(),
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: SizeConfig.heightMultiplier * 2.5,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 5.0),
|
|
|
|
|
child: AppText(
|
|
|
|
|
TranslationBase.of(context).searchMedicineImageCaption,
|
|
|
|
|
fontSize: SizeConfig.heightMultiplier * 2,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 15,
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
child: Wrap(
|
|
|
|
|
alignment: WrapAlignment.center,
|
|
|
|
|
FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.9,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
// TODO change it secondary button and add loading
|
|
|
|
|
AppButton(
|
|
|
|
|
title: TranslationBase.of(context).search,
|
|
|
|
|
onPressed: () async{
|
|
|
|
|
await searchMedicine(context, model);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
Column(
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
|
left: SizeConfig.heightMultiplier * 2),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
AppText(
|
|
|
|
|
TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.youCanFind +
|
|
|
|
|
model.pharmacyItemsList.length
|
|
|
|
|
.toString() +
|
|
|
|
|
" " +
|
|
|
|
|
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(8.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(
|
|
|
|
|
decoration: textFieldSelectorDecoration(
|
|
|
|
|
TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.itemsInSearch,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
.searchMedicineNameHere,
|
|
|
|
|
_selectedMedication != null
|
|
|
|
|
? _selectedMedication.description +
|
|
|
|
|
('${_selectedMedication.genericName}')
|
|
|
|
|
: null,
|
|
|
|
|
true,
|
|
|
|
|
icon: EvaIcons.search),
|
|
|
|
|
enabled: false,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
height: MediaQuery
|
|
|
|
|
.of(context)
|
|
|
|
|
.size
|
|
|
|
|
.height * 0.35,
|
|
|
|
|
child: Container(
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 15,
|
|
|
|
|
),
|
|
|
|
|
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);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Column(
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
|
left: SizeConfig.heightMultiplier * 2),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
AppText(
|
|
|
|
|
TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.youCanFind +
|
|
|
|
|
model.pharmacyItemsList.length
|
|
|
|
|
.toString() +
|
|
|
|
|
" " +
|
|
|
|
|
TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.itemsInSearch,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
height: MediaQuery
|
|
|
|
|
.of(context)
|
|
|
|
|
.size
|
|
|
|
|
.height * 0.35,
|
|
|
|
|
child: Container(
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemCount:
|
|
|
|
|
model.pharmacyItemsList ==
|
|
|
|
|
null
|
|
|
|
|
? 0
|
|
|
|
|
: model
|
|
|
|
|
.pharmacyItemsList.length,
|
|
|
|
|
itemBuilder:
|
|
|
|
|
(BuildContext context, int index) {
|
|
|
|
|
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"],
|
|
|
|
|
label: model.pharmacyItemsList[index]
|
|
|
|
|
["ItemDescription"],
|
|
|
|
|
url: model.pharmacyItemsList[index]
|
|
|
|
|
["ImageSRCUrl"],
|
|
|
|
|
),
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
@ -227,8 +295,8 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) =>
|
|
|
|
|
PharmaciesListScreen(
|
|
|
|
|
itemID: model
|
|
|
|
|
.pharmacyItemsList[
|
|
|
|
|
itemID:
|
|
|
|
|
model.pharmacyItemsList[
|
|
|
|
|
index]["ItemID"],
|
|
|
|
|
url: model
|
|
|
|
|
.pharmacyItemsList[
|
|
|
|
|
@ -237,31 +305,32 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),),);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchMedicine(context, MedicineViewModel model) async {
|
|
|
|
|
FocusScope.of(context).unfocus();
|
|
|
|
|
if (myController.text.isNullOrEmpty()) {
|
|
|
|
|
if (_selectedMedication.isNullOrEmpty()) {
|
|
|
|
|
helpers.showErrorToast(TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.typeMedicineName);
|
|
|
|
|
//"Type Medicine Name")
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (myController.text.length < 3) {
|
|
|
|
|
} else
|
|
|
|
|
if (_selectedMedication.description.length < 3) {
|
|
|
|
|
helpers.showErrorToast(TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.moreThan3Letter);
|
|
|
|
|
@ -270,7 +339,7 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
|
|
|
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
|
|
|
|
|
await model.getMedicineItem(myController.text);
|
|
|
|
|
await model.getMedicineItem(_selectedMedication.description);
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|