From 91cc76a9cfb76d3402a7b0d8960cd7cd418159f1 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 26 Oct 2020 09:23:11 +0300 Subject: [PATCH] medicine search fix bugs = --- lib/config/localized_values.dart | 7 + lib/screens/dashboard_screen.dart | 16 +- .../medicine/medicine_search_screen.dart | 298 ++++++++++-------- .../medicine/pharmacies_list_screen.dart | 4 +- lib/screens/patients/patients_screen.dart | 118 +++---- lib/util/translations_delegate_base.dart | 2 + 6 files changed, 240 insertions(+), 205 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 41dbf5d1..f9022bd3 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -242,4 +242,11 @@ const Map> localizedValues = { 'en': 'You don\'t have any Items', 'ar': 'لا يوجد اي نتائج' }, + 'typeMedicineName': { + 'en': 'Type Medicine Name', + 'ar': 'اكتب اسم الدواء' + },'moreThan3Letter': { + 'en': 'Medicine Name Should Be More Than 3 letter', + 'ar': 'يجب أن يكون اسم الدواء أكثر من 3 أحرف' + }, }; diff --git a/lib/screens/dashboard_screen.dart b/lib/screens/dashboard_screen.dart index b793fe5b..18d70904 100644 --- a/lib/screens/dashboard_screen.dart +++ b/lib/screens/dashboard_screen.dart @@ -441,6 +441,7 @@ class _DashboardScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Container( + margin: EdgeInsets.only(top: 10), child: Icon( DoctorApp.radiology, size: 40, @@ -448,6 +449,8 @@ class _DashboardScreenState extends State { ), ), Container( + margin: EdgeInsets.only(bottom: 10), + child: Column( children: [ AppText( @@ -651,7 +654,6 @@ class _DashboardScreenState extends State { DashboardItem( child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.center, children: [ Center( child: Icon( @@ -777,14 +779,18 @@ class _DashboardScreenState extends State { Column( children: [ AppText( - TranslationBase - .of(context) - .qr, + projectsProvider.isArabic + ? TranslationBase.of(context).reader + : TranslationBase.of(context).qr, color: Colors.black, textAlign: TextAlign.center, ), AppText( - TranslationBase + projectsProvider.isArabic + ? TranslationBase + .of(context) + .qr + : TranslationBase .of(context) .reader, color: Colors.black, diff --git a/lib/screens/medicine/medicine_search_screen.dart b/lib/screens/medicine/medicine_search_screen.dart index 3db62d00..764c1b34 100644 --- a/lib/screens/medicine/medicine_search_screen.dart +++ b/lib/screens/medicine/medicine_search_screen.dart @@ -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 { bool _isInit = true; final SpeechToText speech = SpeechToText(); String lastStatus = ''; + // String lastWords; List _localeNames = []; String lastError; @@ -50,6 +53,7 @@ class _MedicineSearchState extends State { double minSoundLevel = 50000; double maxSoundLevel = -50000; String reconizedWord; + @override void didChangeDependencies() { super.didChangeDependencies(); @@ -92,152 +96,160 @@ class _MedicineSearchState extends State { appBarTitle: TranslationBase.of(context).searchMedicine, body: FractionallySizedBox( widthFactor: 0.97, - child: ListView( - children: [ - Column( - children: [ - 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: [ + Column( children: [ 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: [ - 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: [ + 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: [ - 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: [ + 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: [ + 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 { 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); diff --git a/lib/screens/medicine/pharmacies_list_screen.dart b/lib/screens/medicine/pharmacies_list_screen.dart index 04e60d58..dd0a3649 100644 --- a/lib/screens/medicine/pharmacies_list_screen.dart +++ b/lib/screens/medicine/pharmacies_list_screen.dart @@ -80,8 +80,8 @@ class _PharmaciesListState extends State { child: ClipRRect( borderRadius: BorderRadius.all( Radius.circular(7)), - child: widget.url != null ?Image.memory( - dataFromBase64String(widget.url), + child: widget.url != null ?Image.network( + widget.url, height: SizeConfig.imageSizeMultiplier * 21, diff --git a/lib/screens/patients/patients_screen.dart b/lib/screens/patients/patients_screen.dart index 71281e0f..dc1eda67 100644 --- a/lib/screens/patients/patients_screen.dart +++ b/lib/screens/patients/patients_screen.dart @@ -625,65 +625,67 @@ class _PatientsScreenState extends State { } Widget _locationBar(BuildContext _context) { - return Container( - height: MediaQuery - .of(context) - .size - .height * 0.065, - width: SizeConfig.screenWidth * 0.95, - decoration: BoxDecoration( - color: Color(0Xffffffff), borderRadius: BorderRadius.circular(20)), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.center, - children: _locations.map((item) { - bool _isActive = _locations[_activeLocation] == item ? true : false; - return Column(mainAxisSize: MainAxisSize.min, children: [ - InkWell( - child: Center( - child: Container( - height: 40, - width: 90, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(50), - color: _isActive ? Hexcolor("#B8382B") : Colors.white, - ), - child: Center( - child: Text( - item, - style: TextStyle( - fontSize: 12, - color: _isActive - ? Colors.white - : Colors.black, //Colors.black, - - fontWeight: FontWeight.bold, - ), + return Expanded( + child: Container( + height: MediaQuery + .of(context) + .size + .height * 0.065, + width: SizeConfig.screenWidth * 0.95, + decoration: BoxDecoration( + color: Color(0Xffffffff), borderRadius: BorderRadius.circular(20)), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.center, + children: _locations.map((item) { + bool _isActive = _locations[_activeLocation] == item ? true : false; + return Column(mainAxisSize: MainAxisSize.min, children: [ + InkWell( + child: Center( + child: Container( + height: 40, + width: 90, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(50), + color: _isActive ? Hexcolor("#B8382B") : Colors.white, ), - )), - ), - onTap: () { - print(_locations.indexOf(item)); - - filterBooking(item.toString()); - - setState(() { - _activeLocation = _locations.indexOf(item); - }); - }), - _isActive - ? Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white), - alignment: Alignment.center, - height: 3, - width: 90, - ) - : Container() - ]); - }).toList(), + child: Center( + child: Text( + item, + style: TextStyle( + fontSize: 12, + color: _isActive + ? Colors.white + : Colors.black, //Colors.black, + + fontWeight: FontWeight.bold, + ), + ), + )), + ), + onTap: () { + print(_locations.indexOf(item)); + + filterBooking(item.toString()); + + setState(() { + _activeLocation = _locations.indexOf(item); + }); + }), + _isActive + ? Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white), + alignment: Alignment.center, + height: 3, + width: 90, + ) + : Container() + ]); + }).toList(), + ), ), ); } diff --git a/lib/util/translations_delegate_base.dart b/lib/util/translations_delegate_base.dart index 9793bfa3..7351ed01 100644 --- a/lib/util/translations_delegate_base.dart +++ b/lib/util/translations_delegate_base.dart @@ -271,6 +271,8 @@ class TranslationBase { localizedValues['searchPatientImageCaptionBody'][locale.languageCode]; String get welcome => localizedValues['welcome'][locale.languageCode]; + String get typeMedicineName => localizedValues['typeMedicineName'][locale.languageCode]; + String get moreThan3Letter => localizedValues['moreThan3Letter'][locale.languageCode]; } class TranslationBaseDelegate extends LocalizationsDelegate {