PAP-681 fixed, H2O Unit changing & reflection.

merge-requests/317/head
Sikander Saleem 3 years ago
parent e41040b1b9
commit 1f01f40ad8

@ -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": {

@ -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';

@ -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<H2oSetting> {
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<H2oSetting> {
_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<H2oSetting> {
// 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<H2oSetting> {
]);
}
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<H2oSetting> {
_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);

@ -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<bool> readPrefs() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return (prefs.getString(H2O_UNIT) ?? "ml") == "ml" ? true : false;
}
@override
Widget build(BuildContext context) {
return BaseView<H2OViewModel>(
@ -34,9 +41,29 @@ class TodayPage extends StatelessWidget {
: (model.userProgressData.percentageConsumed / 100) >= 1
? 1
: (model.userProgressData.percentageConsumed / 100),
//,
center: Center(
child: Column(
child: FutureBuilder<bool>(
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(
@ -50,9 +77,7 @@ class TodayPage extends StatelessWidget {
height: 4,
),
Text(
model.userProgressData == null
? "0.0"
: model.userProgressData.quantityConsumed.toString() + TranslationBase.of(context).ml,
model.userProgressData == null ? "0.0" : "$consumedH2O $unit",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14.0, color: HexColor("#60BCF9")),
),
SizedBox(
@ -76,13 +101,14 @@ class TodayPage extends StatelessWidget {
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}',
: (remainingH2O) < 0
? "0 $unit"
: '$remainingH2O $unit',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14.0),
),
],
);
},
),
),
circularStrokeCap: CircularStrokeCap.butt,

Loading…
Cancel
Save