From 1f01f40ad81caa0fcbbbdb9d6e0364a6bbf9fc1e Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Tue, 22 Jun 2021 10:07:55 +0300 Subject: [PATCH] PAP-681 fixed, H2O Unit changing & reflection. --- lib/config/localized_values.dart | 2 +- lib/config/shared_pref_kay.dart | 1 + .../h2o/h20_setting.dart | 30 ++--- .../AlHabibMedicalService/h2o/today_page.dart | 122 +++++++++++------- 4 files changed, 91 insertions(+), 64 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index e5f21342..815cbd3f 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -1808,7 +1808,7 @@ const Map localizedValues = { "drinking": {"en": "Drinkning", "ar": "الشرب"}, "remaining": {"en": "Remaining", "ar": "المتبقي"}, "taken": {"en": "Taken", "ar": " مأخوذ"}, - "ml": {"en": "ml", "ar": "مل"}, + "ml": {"en": "ML", "ar": "مل"}, "l": {"en": "L", "ar": "لتر"}, "custom-label": {"en": "Enter amount", "ar": "أدخل كمية الماء"}, "custom-label-in-litres": { diff --git a/lib/config/shared_pref_kay.dart b/lib/config/shared_pref_kay.dart index caada21f..6e761991 100644 --- a/lib/config/shared_pref_kay.dart +++ b/lib/config/shared_pref_kay.dart @@ -29,3 +29,4 @@ const BLOOD_TYPE = 'blood-type'; const NOTIFICATION_COUNT = 'notification-count'; const PHARMACY_SELECTED_ADDRESS = 'selected-address'; const PHARMACY_AUTORZIE_TOKEN = 'PHARMACY_AUTORZIE_TOKEN'; +const H2O_UNIT = 'H2O_UNIT'; diff --git a/lib/pages/AlHabibMedicalService/h2o/h20_setting.dart b/lib/pages/AlHabibMedicalService/h2o/h20_setting.dart index 4295558a..4acc7eaf 100644 --- a/lib/pages/AlHabibMedicalService/h2o/h20_setting.dart +++ b/lib/pages/AlHabibMedicalService/h2o/h20_setting.dart @@ -1,3 +1,4 @@ +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/H2O/user_detail_model.dart'; import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/H2O_service.dart'; import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/H2O_view_model.dart'; @@ -13,6 +14,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/painting.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import 'Dialog/setting_page_radio_button_list_dialog.dart'; @@ -31,7 +33,7 @@ class _H2oSettingState extends State { TextEditingController _nameController = TextEditingController(); TextEditingController _heightController = TextEditingController(); TextEditingController _weightController = TextEditingController(); - bool _isUnitML = false; + bool _isUnitML = true; bool _isGenderMale = false; bool _isHeightCM = false; bool _isWeightKG = false; @@ -61,6 +63,14 @@ class _H2oSettingState extends State { _isGenderMale = _userDetailModel.gender == "M" ? true : false; _dobDate = DateUtil.convertStringToDate(_userDetailModel.dOB); _selectedActiveLevel = _userDetailModel.activityID ?? 1; + readPrefs(); + } + + SharedPreferences prefs; + void readPrefs() async { + prefs = await SharedPreferences.getInstance(); + _isUnitML = (prefs.getString(H2O_UNIT) ?? "ml") == "ml" ? true : false; + setState(() {}); } @override @@ -68,19 +78,9 @@ class _H2oSettingState extends State { // TODO: implement didChangeDependencies super.didChangeDependencies(); - _activityLevelListEng = [ - TranslationBase.of(context).notActive, - TranslationBase.of(context).lightActive, - TranslationBase.of(context).modActive, - TranslationBase.of(context).active - ]; + _activityLevelListEng = [TranslationBase.of(context).notActive, TranslationBase.of(context).lightActive, TranslationBase.of(context).modActive, TranslationBase.of(context).active]; - _remindedTimeListEng = [ - "1 ${TranslationBase.of(context).time}", - "2 ${TranslationBase.of(context).times}", - "3 ${TranslationBase.of(context).times}", - "4 ${TranslationBase.of(context).times}" - ]; + _remindedTimeListEng = ["1 ${TranslationBase.of(context).time}", "2 ${TranslationBase.of(context).times}", "3 ${TranslationBase.of(context).times}", "4 ${TranslationBase.of(context).times}"]; } @override @@ -339,8 +339,7 @@ class _H2oSettingState extends State { ]); } - Widget _commonSlidersRow( - _controller, double _minValue, double _maxValue, double _valueOrg, Function(String) onTextValueChange, Function(double) onValueChange) { + Widget _commonSlidersRow(_controller, double _minValue, double _maxValue, double _valueOrg, Function(String) onTextValueChange, Function(double) onValueChange) { return Container( margin: EdgeInsets.only(top: 6), padding: EdgeInsets.all(6), @@ -451,6 +450,7 @@ class _H2oSettingState extends State { _userDetailModel.dOB = tempDate; _userDetailModel.activityID = _selectedActiveLevel; GifLoaderDialogUtils.showMyDialog(context); + await prefs.setString(H2O_UNIT, _isUnitML ? "ml" : "l"); await widget.viewModel.updateUserDetail(_userDetailModel, (tag) { if (tag) { AppToast.showSuccessToast(message: TranslationBase.of(context).success); diff --git a/lib/pages/AlHabibMedicalService/h2o/today_page.dart b/lib/pages/AlHabibMedicalService/h2o/today_page.dart index 33383287..e52d2732 100644 --- a/lib/pages/AlHabibMedicalService/h2o/today_page.dart +++ b/lib/pages/AlHabibMedicalService/h2o/today_page.dart @@ -1,3 +1,4 @@ +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/H2O_view_model.dart'; import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/h2o/widgets/h20_floating_action_button.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; @@ -7,8 +8,14 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:percent_indicator/circular_percent_indicator.dart'; +import 'package:shared_preferences/shared_preferences.dart'; class TodayPage extends StatelessWidget { + Future readPrefs() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + return (prefs.getString(H2O_UNIT) ?? "ml") == "ml" ? true : false; + } + @override Widget build(BuildContext context) { return BaseView( @@ -34,55 +41,74 @@ class TodayPage extends StatelessWidget { : (model.userProgressData.percentageConsumed / 100) >= 1 ? 1 : (model.userProgressData.percentageConsumed / 100), - //, center: Center( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - // SizedBox( - // height: 40, - // ), - Text( - TranslationBase.of(context).consumed, - style: TextStyle(fontSize: 16.0), - ), - SizedBox( - height: 4, - ), - Text( - model.userProgressData == null - ? "0.0" - : model.userProgressData.quantityConsumed.toString() + TranslationBase.of(context).ml, - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14.0, color: HexColor("#60BCF9")), - ), - SizedBox( - height: 4, - ), - SizedBox( - height: 5, - width: 50, - child: Container(), - ), - SizedBox( - height: 4, - ), - Text( - TranslationBase.of(context).remaining, - style: TextStyle(fontSize: 16.0), - ), - SizedBox( - height: 4, - ), - Text( - model.userProgressData == null - ? "0.0" - : (model.userProgressData.quantityLimit - model.userProgressData.quantityConsumed) < 0 - ? "0 ${TranslationBase.of(context).ml}" - : (model.userProgressData.quantityLimit - model.userProgressData.quantityConsumed).toString() + - ' ${TranslationBase.of(context).ml}', - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14.0), - ), - ], + child: FutureBuilder( + future: readPrefs(), + builder: (context, data) { + var isUnitML = true; + var unit; + if (data.connectionState == ConnectionState.done) { + isUnitML = data.data; + } + if (isUnitML) { + unit = TranslationBase.of(context).ml; + } else { + unit = TranslationBase.of(context).l; + } + var totalH2O = model?.userProgressData?.quantityLimit ?? 0.0; + var consumedH2O = model?.userProgressData?.quantityConsumed ?? 0.0; + if (!isUnitML) { + totalH2O = totalH2O / 1000; + consumedH2O = consumedH2O / 1000; + } + var remainingH2O = totalH2O - consumedH2O; + + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + // SizedBox( + // height: 40, + // ), + Text( + TranslationBase.of(context).consumed, + style: TextStyle(fontSize: 16.0), + ), + SizedBox( + height: 4, + ), + Text( + model.userProgressData == null ? "0.0" : "$consumedH2O $unit", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14.0, color: HexColor("#60BCF9")), + ), + SizedBox( + height: 4, + ), + SizedBox( + height: 5, + width: 50, + child: Container(), + ), + SizedBox( + height: 4, + ), + Text( + TranslationBase.of(context).remaining, + style: TextStyle(fontSize: 16.0), + ), + SizedBox( + height: 4, + ), + Text( + model.userProgressData == null + ? "0.0" + : (remainingH2O) < 0 + ? "0 $unit" + : '$remainingH2O $unit', + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14.0), + ), + ], + ); + }, ), ), circularStrokeCap: CircularStrokeCap.butt,