From 58d5734f1a4efff666a6b7b8e5a36cad72709641 Mon Sep 17 00:00:00 2001 From: "Mirza.Shafique" Date: Wed, 14 Jul 2021 11:32:37 +0300 Subject: [PATCH] Bug Fix: 873, 878 to 881 --- lib/core/model/feedback/COC_items.dart | 57 ++++---- lib/core/viewModels/project_view_model.dart | 19 ++- lib/main.dart | 7 +- lib/pages/base/base_view.dart | 7 +- lib/pages/feedback/send_feedback_page.dart | 76 ++++++----- lib/pages/landing/home_page.dart | 26 ++-- lib/pages/medical/balance/new_text_Field.dart | 4 +- .../my_trackers/Weight/AddWeightPage.dart | 105 +++++++++------ .../blood_pressure/AddBloodPressurePage.dart | 125 ++++++++++++------ .../blood_suger/AddBloodSugarPage.dart | 87 +++++++----- lib/uitl/date_uitl.dart | 1 - lib/widgets/LoadingButton.dart | 49 +++---- 12 files changed, 335 insertions(+), 228 deletions(-) diff --git a/lib/core/model/feedback/COC_items.dart b/lib/core/model/feedback/COC_items.dart index 068c8bee..2748ca50 100644 --- a/lib/core/model/feedback/COC_items.dart +++ b/lib/core/model/feedback/COC_items.dart @@ -27,34 +27,35 @@ class COCItem { String statusAr; dynamic statusEn; - COCItem( - {this.appointment, - this.appointmentClinicName, - this.appointmentDate, - this.appointmentProjectName, - this.cOCID, - this.cOCTitle, - this.channel, - this.clinic, - this.clinicID, - this.date, - this.detail, - this.doctor, - this.doctorID, - this.formType, - this.formTypeID, - this.identificationNo, - this.itemID, - this.mobileNo, - this.naturename, - this.patientID, - this.patientName, - this.project, - this.projectID, - this.solution, - this.status, - this.statusAr, - this.statusEn}); + COCItem({ + this.appointment, + this.appointmentClinicName, + this.appointmentDate, + this.appointmentProjectName, + this.cOCID, + this.cOCTitle, + this.channel, + this.clinic, + this.clinicID, + this.date, + this.detail, + this.doctor, + this.doctorID, + this.formType, + this.formTypeID, + this.identificationNo, + this.itemID, + this.mobileNo, + this.naturename, + this.patientID, + this.patientName, + this.project, + this.projectID, + this.solution, + this.status, + this.statusAr, + this.statusEn, + }); COCItem.fromJson(Map json) { appointment = json['Appointment']; diff --git a/lib/core/viewModels/project_view_model.dart b/lib/core/viewModels/project_view_model.dart index 2bb75305..17ccb267 100644 --- a/lib/core/viewModels/project_view_model.dart +++ b/lib/core/viewModels/project_view_model.dart @@ -36,7 +36,6 @@ class ProjectViewModel extends BaseViewModel { bool get isArabic => _isArabic; - bool isLoginChild = false; List privilegeRootUser = List(); List privilegeChildUser = List(); @@ -67,7 +66,8 @@ class ProjectViewModel extends BaseViewModel { } Future loadSharedPrefLanguage() async { - currentLanguage = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar'); + currentLanguage = + await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar'); _appLocale = Locale(currentLanguage); _isArabic = currentLanguage == 'ar'; notifyListeners(); @@ -89,10 +89,9 @@ class ProjectViewModel extends BaseViewModel { notifyListeners(); } - setPrivilegeModelList( - {List privilege}) { + setPrivilegeModelList({List privilege}) { this.isLoginChild = isLoginChild; - privilegeRootUser = privilege; + privilegeRootUser = privilege; notifyListeners(); } @@ -113,18 +112,18 @@ class ProjectViewModel extends BaseViewModel { notifyListeners(); } - setIsLoginChild({@required bool isLoginChild}){ + setIsLoginChild({@required bool isLoginChild}) { this.isLoginChild = isLoginChild; notifyListeners(); } bool havePrivilege(int id) { bool isHavePrivilege = false; - if(isLoginChild) + if (isLoginChild) privilegeChildUser.forEach((element) { - if (element.iD == id) isHavePrivilege = element.privilege; - }); - else{ + if (element.iD == id) isHavePrivilege = element.privilege; + }); + else { privilegeRootUser.forEach((element) { if (element.iD == id) isHavePrivilege = element.privilege; }); diff --git a/lib/main.dart b/lib/main.dart index 2412e4d1..70ca9d71 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -36,7 +36,7 @@ class MyApp extends StatefulWidget { class _MyApp extends State { @override - void initState(){ + void initState() { // ProjectViewModel projectProvider; // projectProvider = Provider.of(context); // var font = projectProvider.isArabic ? 'Cairo' : 'WorkSans'; @@ -72,10 +72,7 @@ class _MyApp extends State { value: SearchProvider(), ), ChangeNotifierProvider( - create: (context) => ThemeNotifier( - defaultTheme() - ) - ), + create: (context) => ThemeNotifier(defaultTheme())), StreamProvider.value( value: RobotProvider().intStream(), initialData: RobotProvider().setValue({}), diff --git a/lib/pages/base/base_view.dart b/lib/pages/base/base_view.dart index 5977e97e..ba274bdd 100644 --- a/lib/pages/base/base_view.dart +++ b/lib/pages/base/base_view.dart @@ -33,10 +33,10 @@ class _BaseViewState extends State> { @override void initState() { - if(widget.allowAny && widget.onModelReady != null){ + if (widget.allowAny && widget.onModelReady != null) { widget.onModelReady(model); - } - else if (widget.onModelReady != null && Provider.of(context, listen: false).isLogin) { + } else if (widget.onModelReady != null && + Provider.of(context, listen: false).isLogin) { widget.onModelReady(model); } super.initState(); @@ -60,7 +60,6 @@ class _BaseViewState extends State> { if (model != null) { model = null; } - super.dispose(); } } diff --git a/lib/pages/feedback/send_feedback_page.dart b/lib/pages/feedback/send_feedback_page.dart index 8ebdabd8..fca9624c 100644 --- a/lib/pages/feedback/send_feedback_page.dart +++ b/lib/pages/feedback/send_feedback_page.dart @@ -44,6 +44,7 @@ class _SendFeedbackPageState extends State { stt.SpeechToText speech = stt.SpeechToText(); var reconizedWord; var event = RobotProvider(); + String getSelected(BuildContext context) { switch (messageType) { case MessageType.ComplaintOnAnAppointment: @@ -325,6 +326,9 @@ class _SendFeedbackPageState extends State { fontSize: 13.5, hintColor: Colors.black, fontWeight: FontWeight.w600, + onChanged: (v){setState(() { + + });}, validator: (value) { if (value.isEmpty) return TranslationBase.of(context).emptySubject; @@ -347,6 +351,9 @@ class _SendFeedbackPageState extends State { onSuffixTap: () { openSpeechReco(); }, + onChanged: (v){setState(() { + + });}, validator: (value) { if (value.isEmpty) return TranslationBase.of(context).emptyMessage; @@ -440,41 +447,39 @@ class _SendFeedbackPageState extends State { label: TranslationBase.of(context).send, textColor: Colors.white, disabled: (titleController.text.toString().isEmpty || - messageController.text.toString().isEmpty || - messageType == MessageType.NON), + messageController.text.toString().isEmpty ), onTap: () { final form = formKey.currentState; - if (form.validate()) if (messageType != MessageType.NON) { - GifLoaderDialogUtils.showMyDialog(context); - model - .sendCOCItem( - title: titleController.text, - attachment: images.length > 0 ? images[0] : "", - details: messageController.text, - cOCTypeName: getCOCName(), - appointHistory: messageType == - MessageType.ComplaintOnAnAppointment - ? appointHistory - : null) - .then((value) { - if (value) { - setState(() { - titleController.text = ""; - messageController.text = ""; - images = []; - }); - setMessageType(MessageType.NON); - GifLoaderDialogUtils.hideDialog(context); - AppToast.showSuccessToast( - message: TranslationBase.of(context).yourFeedback); - } else { - AppToast.showErrorToast(message: model.error); - GifLoaderDialogUtils.hideDialog(context); - } - }); - } else { - AppToast.showErrorToast( - message: TranslationBase.of(context).selectPart); + if (form.validate()) { + + GifLoaderDialogUtils.showMyDialog(context); + model + .sendCOCItem( + title: titleController.text, + attachment: images.length > 0 ? images[0] : "", + details: messageController.text, + cOCTypeName: getCOCName(), + appointHistory: messageType == + MessageType.ComplaintOnAnAppointment + ? appointHistory + : null) + .then((value) { + if (value) { + setState(() { + titleController.text = ""; + messageController.text = ""; + images = []; + }); + setMessageType(MessageType.NON); + GifLoaderDialogUtils.hideDialog(context); + AppToast.showSuccessToast( + message: TranslationBase.of(context).yourFeedback); + } else { + AppToast.showErrorToast(message: model.error); + GifLoaderDialogUtils.hideDialog(context); + } + }); + } }, ), @@ -500,10 +505,10 @@ class _SendFeedbackPageState extends State { return "4"; break; case MessageType.Suggestion: - return "5"; + return "6"; break; case MessageType.NON: - return ""; + return "5"; break; } return ""; @@ -583,6 +588,7 @@ class FeedbackTypeDialogState extends State { setMessageDialogType(MessageType messageType) { setState(() { + messageTypeDialog = messageType; }); } diff --git a/lib/pages/landing/home_page.dart b/lib/pages/landing/home_page.dart index d1b8d4f3..51692461 100644 --- a/lib/pages/landing/home_page.dart +++ b/lib/pages/landing/home_page.dart @@ -156,15 +156,23 @@ class _HomePageState extends State { onPressed: () { navigateToCovidDriveThru(); }, - child: Texts( - TranslationBase.of( - context) - .bookNow, - fontWeight: - FontWeight - .w700, - color: Colors - .white, + child: Center( + child: Center( + child: Center( + child: Center( + child: Texts( + TranslationBase.of( + context) + .bookNow, + fontWeight: + FontWeight + .w700, + color: Colors + .white, + ), + ), + ), + ), ), ), ), diff --git a/lib/pages/medical/balance/new_text_Field.dart b/lib/pages/medical/balance/new_text_Field.dart index f61c7267..3e20dc00 100644 --- a/lib/pages/medical/balance/new_text_Field.dart +++ b/lib/pages/medical/balance/new_text_Field.dart @@ -74,7 +74,7 @@ class NewTextFields extends StatefulWidget { this.fontWeight = FontWeight.w700, this.autoValidate = false, this.hintColor, - this.isEnabled = true}) + this.isEnabled = true,this.counterText=""}) : super(key: key); final String hintText; @@ -112,6 +112,7 @@ class NewTextFields extends StatefulWidget { final bool borderOnlyError; final Color hintColor; final String initialValue; + final String counterText; @override _NewTextFieldsState createState() => _NewTextFieldsState(); } @@ -199,6 +200,7 @@ class _NewTextFieldsState extends State { : widget.inputFormatters, decoration: InputDecoration( labelText: widget.hintText, + counterText: widget.counterText, labelStyle: TextStyle(color: Theme.of(context).textTheme.bodyText1.color), errorBorder: OutlineInputBorder( diff --git a/lib/pages/medical/my_trackers/Weight/AddWeightPage.dart b/lib/pages/medical/my_trackers/Weight/AddWeightPage.dart index 71799084..62f4e878 100644 --- a/lib/pages/medical/my_trackers/Weight/AddWeightPage.dart +++ b/lib/pages/medical/my_trackers/Weight/AddWeightPage.dart @@ -51,6 +51,7 @@ class _AddWeightPageState extends State { ]; final List measureUnitArList = ["كيلو جرام", "باوند"]; String measureTimeSelectedType; + bool isButtonDisabled = false; @override void initState() { @@ -64,6 +65,7 @@ class _AddWeightPageState extends State { else if (measureUnitArList.contains(widget.measureTimeSelectedType)) weightUnit = measureUnitArList.indexOf(widget.measureTimeSelectedType); _weightValueController.text = widget.weightValue; + validateForm(); } } @@ -76,40 +78,41 @@ class _AddWeightPageState extends State { appBarTitle: widget.isUpdate ? TranslationBase.of(context).update : TranslationBase.of(context).add, - appBarIcons:widget.isUpdate? [ - IconButton( - icon: Icon(Icons.delete), - color: Colors.white, - onPressed: () { - ConfirmDialog dialog = new ConfirmDialog( - context: context, - confirmMessage: 'Remove this measure', - okText: TranslationBase.of(context).ok, - cancelText: TranslationBase.of(context).cancel, - okFunction: () async { - ConfirmDialog.closeAlertDialog(context); + appBarIcons: widget.isUpdate + ? [ + IconButton( + icon: Icon(Icons.delete), + color: Colors.white, + onPressed: () { + ConfirmDialog dialog = new ConfirmDialog( + context: context, + confirmMessage: 'Remove this measure', + okText: TranslationBase.of(context).ok, + cancelText: TranslationBase.of(context).cancel, + okFunction: () async { + ConfirmDialog.closeAlertDialog(context); - GifLoaderDialogUtils.showMyDialog(context); - widget.model - .deleteWeightResult(lineItemNo: widget.lineItemNo) - .then((value) { - GifLoaderDialogUtils.hideDialog(context); - if (widget.model.state == ViewState.ErrorLocal) - AppToast.showErrorToast( - message: widget.model.error); - else - Navigator.pop(context); - }).catchError((e) { - GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast( - message: widget.model.error); - }); - }, - cancelFunction: () => {}); - dialog.showAlertDialog(context); - }, - ) - ]:null, + GifLoaderDialogUtils.showMyDialog(context); + widget.model + .deleteWeightResult(lineItemNo: widget.lineItemNo) + .then((value) { + GifLoaderDialogUtils.hideDialog(context); + if (widget.model.state == ViewState.ErrorLocal) + AppToast.showErrorToast( + message: widget.model.error); + else + Navigator.pop(context); + }).catchError((e) { + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: widget.model.error); + }); + }, + cancelFunction: () => {}); + dialog.showAlertDialog(context); + }, + ) + ] + : null, body: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Container( @@ -123,6 +126,7 @@ class _AddWeightPageState extends State { hintText: TranslationBase.of(context).weightAdd, controller: _weightValueController, keyboardType: TextInputType.number, + onChanged: (value) => validateForm(), ), SizedBox( height: 8, @@ -235,16 +239,19 @@ class _AddWeightPageState extends State { loading: widget.model.state == ViewState.BusyLocal, label: TranslationBase.of(context).save.toUpperCase(), textColor: Colors.white, + color: isButtonDisabled ? Colors.grey[900] : Colors.grey, onTap: () { if (_weightValueController.text.isNotEmpty) { if (widget.isUpdate) { GifLoaderDialogUtils.showMyDialog(context); - widget.model.updateWeightResult( - weightDate: '${dayWeightDate.year}-${dayWeightDate.month}-${dayWeightDate.day} ${timeWeightDate.hour}:${timeWeightDate.minute}:00', - weightMeasured: _weightValueController.text.toString(), - weightUnit: weightUnit, - lineItemNo: widget.lineItemNo - ) + widget.model + .updateWeightResult( + weightDate: + '${dayWeightDate.year}-${dayWeightDate.month}-${dayWeightDate.day} ${timeWeightDate.hour}:${timeWeightDate.minute}:00', + weightMeasured: + _weightValueController.text.toString(), + weightUnit: weightUnit, + lineItemNo: widget.lineItemNo) .then((value) { GifLoaderDialogUtils.hideDialog(context); if (widget.model.state == ViewState.Error) @@ -253,8 +260,10 @@ class _AddWeightPageState extends State { Navigator.pop(context); }); } else - widget.model.addWeightResult( - weightDate: '${dayWeightDate.year}-${dayWeightDate.month}-${dayWeightDate.day} ${timeWeightDate.hour}:${timeWeightDate.minute}:00', + widget.model + .addWeightResult( + weightDate: + '${dayWeightDate.year}-${dayWeightDate.month}-${dayWeightDate.day} ${timeWeightDate.hour}:${timeWeightDate.minute}:00', weightMeasured: _weightValueController.text.toString(), weightUnit: weightUnit, ) @@ -291,9 +300,23 @@ class _AddWeightPageState extends State { setState(() { measureTimeSelectedType = value; weightUnit = list.indexOf(value); + validateForm(); }); }, ), ); } + + void validateForm() { + if (_weightValueController.text.length > 0 && + measureTimeSelectedType != null) { + setState(() { + isButtonDisabled = true; + }); + } else { + setState(() { + isButtonDisabled = false; + }); + } + } } diff --git a/lib/pages/medical/my_trackers/blood_pressure/AddBloodPressurePage.dart b/lib/pages/medical/my_trackers/blood_pressure/AddBloodPressurePage.dart index 678ef7dc..ade2c366 100644 --- a/lib/pages/medical/my_trackers/blood_pressure/AddBloodPressurePage.dart +++ b/lib/pages/medical/my_trackers/blood_pressure/AddBloodPressurePage.dart @@ -29,7 +29,7 @@ class AddBloodPressurePage extends StatefulWidget { {Key key, this.bloodSugarDate, this.measureTimeSelectedType, - this.isUpdate=false, + this.isUpdate = false, this.lineItemNo, this.model, this.bloodSystolicValue, @@ -47,6 +47,7 @@ class _AddBloodPressurePageState extends State { DateTime bloodSugarDate = DateTime.now(); DateTime timeSugarDate = DateTime.now(); int measuredArm = 1; + bool isButtonDisabled = false; final List measureTimeEnList = [ 'Left', 'Right', @@ -70,6 +71,7 @@ class _AddBloodPressurePageState extends State { measuredArm = measureTimeArList.indexOf(widget.measureTimeSelectedType); _bloodSystolicValueController.text = widget.bloodSystolicValue; _bloodDiastolicValueController.text = widget.bloodDiastolicValue; + validateForm(); } } @@ -82,38 +84,42 @@ class _AddBloodPressurePageState extends State { appBarTitle: widget.isUpdate ? TranslationBase.of(context).update : TranslationBase.of(context).add, - appBarIcons: widget.isUpdate?[ - IconButton( - icon: Icon(Icons.delete), - color: Colors.white, - onPressed: () { - ConfirmDialog dialog = new ConfirmDialog( - context: context, - confirmMessage: 'Remove this measure', - okText: TranslationBase.of(context).ok, - cancelText: TranslationBase.of(context).cancel, - okFunction: () async { - ConfirmDialog.closeAlertDialog(context); + appBarIcons: widget.isUpdate + ? [ + IconButton( + icon: Icon(Icons.delete), + color: Colors.white, + onPressed: () { + ConfirmDialog dialog = new ConfirmDialog( + context: context, + confirmMessage: 'Remove this measure', + okText: TranslationBase.of(context).ok, + cancelText: TranslationBase.of(context).cancel, + okFunction: () async { + ConfirmDialog.closeAlertDialog(context); - GifLoaderDialogUtils.showMyDialog(context); - widget.model - .deactivateDiabeticStatus(lineItemNo: widget.lineItemNo) - .then((value) { - GifLoaderDialogUtils.hideDialog(context); - if (widget.model.state == ViewState.ErrorLocal) - AppToast.showErrorToast(message: widget.model.error); - else - Navigator.pop(context); - }).catchError((e) { - GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: widget.model.error); - }); + GifLoaderDialogUtils.showMyDialog(context); + widget.model + .deactivateDiabeticStatus( + lineItemNo: widget.lineItemNo) + .then((value) { + GifLoaderDialogUtils.hideDialog(context); + if (widget.model.state == ViewState.ErrorLocal) + AppToast.showErrorToast( + message: widget.model.error); + else + Navigator.pop(context); + }).catchError((e) { + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: widget.model.error); + }); + }, + cancelFunction: () => {}); + dialog.showAlertDialog(context); }, - cancelFunction: () => {}); - dialog.showAlertDialog(context); - }, - ) - ]:null, + ) + ] + : null, body: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Container( @@ -127,6 +133,8 @@ class _AddBloodPressurePageState extends State { hintText: TranslationBase.of(context).systolicAdd, controller: _bloodSystolicValueController, keyboardType: TextInputType.number, + maxLength: 3, + onChanged: (value) => validateForm(), ), SizedBox( height: 8, @@ -135,6 +143,8 @@ class _AddBloodPressurePageState extends State { hintText: TranslationBase.of(context).diastolicAdd, controller: _bloodDiastolicValueController, keyboardType: TextInputType.number, + maxLength: 3, + onChanged: (value) => validateForm(), ), SizedBox( height: 8, @@ -244,12 +254,16 @@ class _AddBloodPressurePageState extends State { loading: widget.model.state == ViewState.BusyLocal, label: TranslationBase.of(context).save.toUpperCase(), textColor: Colors.white, + color: isButtonDisabled + ? Colors.grey[900] + : Colors.grey, onTap: () async { if (_bloodSystolicValueController.text.isNotEmpty && _bloodDiastolicValueController.text.isNotEmpty) { GifLoaderDialogUtils.showMyDialog(context); - widget.model.addORUpdateDiabtecResult( + widget.model + .addORUpdateDiabtecResult( isUpdate: widget.isUpdate, bloodPressureDate: '${bloodSugarDate.year}-${bloodSugarDate.month}-${bloodSugarDate.day} ${timeSugarDate.hour}:${timeSugarDate.minute}:00', @@ -258,14 +272,15 @@ class _AddBloodPressurePageState extends State { systolicePressure: _bloodSystolicValueController.text.toString(), measuredArm: measuredArm, - ).then((value) { + ) + .then((value) { GifLoaderDialogUtils.hideDialog(context); - if(widget.model.state == ViewState.BusyLocal) - AppToast.showErrorToast(message: widget.model.error); + if (widget.model.state == ViewState.BusyLocal) + AppToast.showErrorToast(message: widget.model.error); else - Navigator.pop(context); -; - }).catchError((e){ + Navigator.pop(context); + ; + }).catchError((e) { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: widget.model.error); }); @@ -295,9 +310,43 @@ class _AddBloodPressurePageState extends State { setState(() { measureTimeSelectedType = value; measuredArm = list.indexOf(value); + validateForm(); }); }, ), ); } + + void validateForm() { + print("_bloodSystolicValueController "+_bloodSystolicValueController.text.length.toString()); + if (measureTimeSelectedType != 'Left Arm' && + _bloodSystolicValueController.text.length > 0 && + _bloodDiastolicValueController.text.length > 0) { + setState(() { + isButtonDisabled = true; + }); + } else { + setState(() { + isButtonDisabled = false; + }); + } + // if(measureTimeSelectedType == 'Left Arm'){ + // setState(() { + // isButtonDisabled = false; + // }); + // }else if(_bloodSystolicValueController.text.length < 0){ + // setState(() { + // isButtonDisabled = false; + // }); + // }else if(_bloodDiastolicValueController.text.length < 0){ + // setState(() { + // isButtonDisabled = false; + // }); + // }else{ + // setState(() { + // isButtonDisabled = true; + // }); + // } + } + } diff --git a/lib/pages/medical/my_trackers/blood_suger/AddBloodSugarPage.dart b/lib/pages/medical/my_trackers/blood_suger/AddBloodSugarPage.dart index 94e48b92..2ed34c0f 100644 --- a/lib/pages/medical/my_trackers/blood_suger/AddBloodSugarPage.dart +++ b/lib/pages/medical/my_trackers/blood_suger/AddBloodSugarPage.dart @@ -46,6 +46,7 @@ class _AddBloodSugarPageState extends State { DateTime timeSugarDate = DateTime.now(); String measureUnitSelectedType = 'mg/dlt'; int measuredTime = 1; + bool isButtonDisabled = false; final List measureUnitList = ['mg/dlt', 'mol/L']; final List measureTimeEnList = [ 'Before Breakfast', @@ -85,6 +86,7 @@ class _AddBloodSugarPageState extends State { else if (measureTimeArList.contains(widget.measuredTime)) measuredTime = measureTimeArList.indexOf(widget.measuredTime); _bloodSugarValueController.text = widget.bloodSugarValue; + validateForm(); } } @@ -96,40 +98,44 @@ class _AddBloodSugarPageState extends State { appBarTitle: widget.isUpdate ? TranslationBase.of(context).update : TranslationBase.of(context).add, - appBarIcons: widget.isUpdate?[ - IconButton( - icon: Icon(Icons.delete), - color: Colors.white, - onPressed: () { - ConfirmDialog dialog = new ConfirmDialog( - context: context, - confirmMessage: 'Remove this measure', - okText: TranslationBase.of(context).ok, - cancelText: TranslationBase.of(context).cancel, - okFunction: () async { - ConfirmDialog.closeAlertDialog(context); + appBarIcons: widget.isUpdate + ? [ + IconButton( + icon: Icon(Icons.delete), + color: Colors.white, + onPressed: () { + ConfirmDialog dialog = new ConfirmDialog( + context: context, + confirmMessage: 'Remove this measure', + okText: TranslationBase.of(context).ok, + cancelText: TranslationBase.of(context).cancel, + okFunction: () async { + ConfirmDialog.closeAlertDialog(context); - GifLoaderDialogUtils.showMyDialog(context); - widget.bloodSugarViewMode - .deactivateDiabeticStatus(lineItemNo: widget.lineItemNo) - .then((value) { - GifLoaderDialogUtils.hideDialog(context); - if (widget.bloodSugarViewMode.state == ViewState.ErrorLocal) - AppToast.showErrorToast( - message: widget.bloodSugarViewMode.error); - else - Navigator.pop(context); - }).catchError((e) { - GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast( - message: widget.bloodSugarViewMode.error); - }); + GifLoaderDialogUtils.showMyDialog(context); + widget.bloodSugarViewMode + .deactivateDiabeticStatus( + lineItemNo: widget.lineItemNo) + .then((value) { + GifLoaderDialogUtils.hideDialog(context); + if (widget.bloodSugarViewMode.state == + ViewState.ErrorLocal) + AppToast.showErrorToast( + message: widget.bloodSugarViewMode.error); + else + Navigator.pop(context); + }).catchError((e) { + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast( + message: widget.bloodSugarViewMode.error); + }); + }, + cancelFunction: () => {}); + dialog.showAlertDialog(context); }, - cancelFunction: () => {}); - dialog.showAlertDialog(context); - }, - ) - ]:null, + ) + ] + : null, body: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Container( @@ -143,6 +149,7 @@ class _AddBloodSugarPageState extends State { hintText: TranslationBase.of(context).sugarAdd, controller: _bloodSugarValueController, keyboardType: TextInputType.number, + onChanged: (value) => validateForm(), ), SizedBox( height: 8, @@ -274,6 +281,7 @@ class _AddBloodSugarPageState extends State { child: SecondaryButton( label: TranslationBase.of(context).save.toUpperCase(), textColor: Colors.white, + color: isButtonDisabled ? Colors.grey[900] : Colors.grey, onTap: () { if (_bloodSugarValueController.text.isNotEmpty) { if (widget.isUpdate) { @@ -289,7 +297,8 @@ class _AddBloodSugarPageState extends State { _bloodSugarValueController.text.toString()) .then((value) { GifLoaderDialogUtils.hideDialog(context); - if (widget.bloodSugarViewMode.state == ViewState.ErrorLocal) + if (widget.bloodSugarViewMode.state == + ViewState.ErrorLocal) AppToast.showErrorToast( message: widget.bloodSugarViewMode.error); else @@ -360,4 +369,16 @@ class _AddBloodSugarPageState extends State { ), ); } + + void validateForm() { + if (_bloodSugarValueController.text.length > 0) { + setState(() { + isButtonDisabled = true; + }); + } else { + setState(() { + isButtonDisabled = false; + }); + } + } } diff --git a/lib/uitl/date_uitl.dart b/lib/uitl/date_uitl.dart index 9f959885..b5d5ab59 100644 --- a/lib/uitl/date_uitl.dart +++ b/lib/uitl/date_uitl.dart @@ -393,7 +393,6 @@ class DateUtil { break; case DayOfWeek.Sunday: return "Sunday"; - break; } return ""; diff --git a/lib/widgets/LoadingButton.dart b/lib/widgets/LoadingButton.dart index 46983903..6924bd44 100644 --- a/lib/widgets/LoadingButton.dart +++ b/lib/widgets/LoadingButton.dart @@ -62,21 +62,21 @@ class _AnimatedButtonState extends State _buttonOpacityAnimation = Tween(begin: 1.0, end: 0.0).animate(CurvedAnimation( - parent: widget.controller, - curve: Threshold(.65), - )); + parent: widget.controller, + curve: Threshold(.65), + )); _ringThicknessAnimation = Tween(begin: _loadingCircleRadius, end: _loadingCircleThickness) .animate(CurvedAnimation( - parent: widget.controller, - curve: Interval(.65, .85), - )); + parent: widget.controller, + curve: Interval(.65, .85), + )); _ringOpacityAnimation = Tween(begin: 1.0, end: 0.0).animate(CurvedAnimation( - parent: widget.controller, - curve: Interval(.85, 1.0), - )); + parent: widget.controller, + curve: Interval(.85, 1.0), + )); widget.controller.addStatusListener(handleStatusChanged); } @@ -161,7 +161,9 @@ class _AnimatedButtonState extends State // button width is min 120.0 and max 240.0 _width = textWidth > 120.0 && textWidth < 240.0 ? textWidth - : textWidth >= 240.0 ? 240.0 : 120.0; + : textWidth >= 240.0 + ? 240.0 + : 120.0; _sizeAnimation = Tween(begin: 1.0, end: _height / _width) .animate(CurvedAnimation( @@ -191,13 +193,14 @@ class _AnimatedButtonState extends State animation: _colorAnimation, builder: (context, child) => Material( shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(_height/2) - ), + borderRadius: BorderRadius.circular(_height / 2)), color: _colorAnimation.value, child: child, shadowColor: _color, elevation: !_isLoading - ? (_hover ? buttonTheme.highlightElevation : buttonTheme.elevation) + ? (_hover + ? buttonTheme.highlightElevation + : buttonTheme.elevation) : 0, ), child: InkWell( @@ -279,15 +282,14 @@ class Ring extends StatelessWidget { child: thickness == 0 ? null : CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation(color), - strokeWidth: thickness, - value: value, - ), + valueColor: AlwaysStoppedAnimation(color), + strokeWidth: thickness, + value: value, + ), ); } } - enum AnimatedTextRotation { up, down } /// https://medium.com/flutter-community/flutter-challenge-3d-bottom-navigation-bar-48952a5fd996 @@ -319,7 +321,6 @@ class _AnimatedTextState extends State double get radius => _layoutHeight / 2; - @override void initState() { super.initState(); @@ -370,7 +371,7 @@ class _AnimatedTextState extends State if (kIsWeb) { return Matrix4.identity(); } - return Matrix4.identity()..setEntry(3, 2, .006); + return Matrix4.identity()..setEntry(3, 2, .006); } Matrix4 _getFrontSideUp(double value) { @@ -452,12 +453,14 @@ class _AnimatedTextState extends State ); } - // Helpers double toRadian(double degree) => degree * pi / 180; - double lerp(double start, double end, double percent) => (start + percent * (end - start)); + + double lerp(double start, double end, double percent) => + (start + percent * (end - start)); + Size getWidgetSize(GlobalKey key) { final RenderBox renderBox = key.currentContext?.findRenderObject(); return renderBox?.size; } -} \ No newline at end of file +}