|
|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
|
|
import 'package:doctor_app_flutter/config/config.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/config/size_config.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
|
|
|
|
|
@ -14,19 +16,19 @@ 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';
|
|
|
|
|
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:speech_to_text/speech_recognition_error.dart';
|
|
|
|
|
import 'package:speech_to_text/speech_recognition_result.dart';
|
|
|
|
|
import 'package:speech_to_text/speech_to_text.dart';
|
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
|
|
import '../../util/extenstions.dart';
|
|
|
|
|
|
|
|
|
|
DrAppSharedPreferances sharedPref = DrAppSharedPreferances();
|
|
|
|
|
|
|
|
|
|
class MedicineSearchScreen extends StatefulWidget with DrAppToastMsg {
|
|
|
|
|
MedicineSearchScreen({this.changeLoadingStata});
|
|
|
|
|
|
|
|
|
|
final Function changeLoadingStata;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
@ -43,6 +45,7 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
|
|
|
bool _isInit = true;
|
|
|
|
|
final SpeechToText speech = SpeechToText();
|
|
|
|
|
String lastStatus = '';
|
|
|
|
|
|
|
|
|
|
// String lastWords;
|
|
|
|
|
List<LocaleName> _localeNames = [];
|
|
|
|
|
String lastError;
|
|
|
|
|
@ -50,6 +53,7 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
|
|
|
double minSoundLevel = 50000;
|
|
|
|
|
double maxSoundLevel = -50000;
|
|
|
|
|
String reconizedWord;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void didChangeDependencies() {
|
|
|
|
|
super.didChangeDependencies();
|
|
|
|
|
@ -92,152 +96,160 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
|
|
|
appBarTitle: TranslationBase.of(context).searchMedicine,
|
|
|
|
|
body: FractionallySizedBox(
|
|
|
|
|
widthFactor: 0.97,
|
|
|
|
|
child: ListView(
|
|
|
|
|
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,
|
|
|
|
|
child: Column(
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
child: AppTextFormField(
|
|
|
|
|
hintText: TranslationBase.of(context).searchMedicineNameHere,
|
|
|
|
|
controller: myController,
|
|
|
|
|
onSaved: (value) {},
|
|
|
|
|
onFieldSubmitted: (value) {
|
|
|
|
|
searchMedicine(context);
|
|
|
|
|
},
|
|
|
|
|
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),
|
|
|
|
|
child: Icon(
|
|
|
|
|
DoctorApp.medicine_search,
|
|
|
|
|
size: 100,
|
|
|
|
|
color: Colors.black,
|
|
|
|
|
),
|
|
|
|
|
margin: EdgeInsets.only(top: 50),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 15,),
|
|
|
|
|
|
|
|
|
|
Container(
|
|
|
|
|
child: Wrap(
|
|
|
|
|
alignment: WrapAlignment.center,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
AppButton(
|
|
|
|
|
title: TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.search,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
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,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
child: AppTextFormField(
|
|
|
|
|
hintText: TranslationBase.of(context)
|
|
|
|
|
.searchMedicineNameHere,
|
|
|
|
|
controller: myController,
|
|
|
|
|
onSaved: (value) {},
|
|
|
|
|
onFieldSubmitted: (value) {
|
|
|
|
|
searchMedicine(context);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
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),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
margin: EdgeInsets.only(left: SizeConfig.heightMultiplier * 2),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
AppText(
|
|
|
|
|
TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.youCanFind +
|
|
|
|
|
_medicineProvider.pharmacyItemsList.length
|
|
|
|
|
.toString() +" "+
|
|
|
|
|
TranslationBase
|
|
|
|
|
.of(context)
|
|
|
|
|
.itemsInSearch,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 15,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
child: !_medicineProvider.isFinished
|
|
|
|
|
? DrAppCircularProgressIndeicator()
|
|
|
|
|
: _medicineProvider.hasError
|
|
|
|
|
? Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
_medicineProvider.errorMsg,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Theme.of(context).errorColor),
|
|
|
|
|
Container(
|
|
|
|
|
child: Wrap(
|
|
|
|
|
alignment: WrapAlignment.center,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
AppButton(
|
|
|
|
|
title: TranslationBase.of(context).search,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
searchMedicine(context);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: ListView.builder(
|
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemCount: _medicineProvider.pharmacyItemsList ==
|
|
|
|
|
null
|
|
|
|
|
? 0
|
|
|
|
|
: _medicineProvider.pharmacyItemsList.length,
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
return InkWell(
|
|
|
|
|
child: MedicineItemWidget(
|
|
|
|
|
label:
|
|
|
|
|
_medicineProvider.pharmacyItemsList[index]
|
|
|
|
|
["ItemDescription"],
|
|
|
|
|
url:
|
|
|
|
|
_medicineProvider.pharmacyItemsList[index]
|
|
|
|
|
["ProductImageBase64"],
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
|
left: SizeConfig.heightMultiplier * 2),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
AppText(
|
|
|
|
|
TranslationBase.of(context).youCanFind +
|
|
|
|
|
_medicineProvider.pharmacyItemsList.length
|
|
|
|
|
.toString() +
|
|
|
|
|
" " +
|
|
|
|
|
TranslationBase.of(context).itemsInSearch,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) =>
|
|
|
|
|
PharmaciesListScreen(
|
|
|
|
|
itemID: _medicineProvider
|
|
|
|
|
.pharmacyItemsList[index]
|
|
|
|
|
["ItemID"],
|
|
|
|
|
url: _medicineProvider
|
|
|
|
|
.pharmacyItemsList[index]
|
|
|
|
|
["ProductImageBase64"]),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
Container(
|
|
|
|
|
height: MediaQuery.of(context).size.height * 0.35,
|
|
|
|
|
child: Container(
|
|
|
|
|
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:
|
|
|
|
|
_medicineProvider.pharmacyItemsList ==
|
|
|
|
|
null
|
|
|
|
|
? 0
|
|
|
|
|
: _medicineProvider
|
|
|
|
|
.pharmacyItemsList.length,
|
|
|
|
|
itemBuilder:
|
|
|
|
|
(BuildContext context, int index) {
|
|
|
|
|
return InkWell(
|
|
|
|
|
child: MedicineItemWidget(
|
|
|
|
|
label: _medicineProvider
|
|
|
|
|
.pharmacyItemsList[index]
|
|
|
|
|
["ItemDescription"],
|
|
|
|
|
url: _medicineProvider
|
|
|
|
|
.pharmacyItemsList[index]
|
|
|
|
|
["ImageSRCUrl"],
|
|
|
|
|
),
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) =>
|
|
|
|
|
PharmaciesListScreen(
|
|
|
|
|
itemID: _medicineProvider
|
|
|
|
|
.pharmacyItemsList[
|
|
|
|
|
index]["ItemID"],
|
|
|
|
|
url: _medicineProvider
|
|
|
|
|
.pharmacyItemsList[
|
|
|
|
|
index]["ImageSRCUrl"]),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
@ -246,7 +258,13 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
|
|
|
|
|
FocusScope.of(context).unfocus();
|
|
|
|
|
if (myController.text.isNullOrEmpty()) {
|
|
|
|
|
_medicineProvider.clearPharmacyItemsList();
|
|
|
|
|
helpers.showErrorToast("Type Medicine Name");
|
|
|
|
|
helpers.showErrorToast(TranslationBase.of(context).typeMedicineName) ;
|
|
|
|
|
//"Type Medicine Name")
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (myController.text.length < 3) {
|
|
|
|
|
_medicineProvider.clearPharmacyItemsList();
|
|
|
|
|
helpers.showErrorToast(TranslationBase.of(context).moreThan3Letter);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_medicineProvider.getMedicineItem(myController.text);
|
|
|
|
|
|