From 9892d7870f10da9ee879163252d6a586d68cf28c Mon Sep 17 00:00:00 2001 From: spinel Date: Mon, 6 Dec 2021 01:11:22 +0100 Subject: [PATCH] fix settings, reevaluate todo list --- TODO | 70 ++++-- lib/models/settings.dart | 33 ++- lib/objectbox-model.json | 22 +- lib/objectbox.g.dart | 57 ++++- lib/screens/bolus/bolus_detail.dart | 24 +- lib/screens/bolus/bolus_list.dart | 2 +- lib/screens/log/log.dart | 14 +- .../log/log_entry/log_bolus_detail.dart | 28 +-- lib/screens/log/log_entry/log_bolus_list.dart | 4 +- lib/screens/log/log_entry/log_entry.dart | 21 +- .../log/log_entry/log_meal_detail.dart | 4 +- lib/screens/meal/meal_detail.dart | 4 +- lib/settings.dart | 212 +++++++++++------- 13 files changed, 320 insertions(+), 175 deletions(-) diff --git a/TODO b/TODO index b74630c..e0485a2 100644 --- a/TODO +++ b/TODO @@ -1,38 +1,74 @@ -MAIN TASKS: - Settings: - ☐ fix settings saving +BUGFIXES: + General/Framework: + ☐ fix preloading of dropdown values (appear blank at first as of now) + ☐ make sure 'null' isn't shown in text fields + Basal/Bolus: + ☐ "no element" error on creating basal/bolus rates when working from apk + ☐ scrollbars in rate overview not showing -FUTURE TASKS: +MAIN TASKS: + Layout: + ☐ make a styleguide (actively decide what components should look like) + ☐ make components rounder/nicer/closer to new material style General/Framework: ☐ show indicator and make all fields readonly if user somehow gets to a deleted record detail view ☐ add functionality to delete dead records (meaning: set deleted flag and no relations) ☐ clean up controllers (dispose method of each stateful widget) - ☐ add explanations to each section - ☐ account for deleted/disabled elements in dropdowns - ☐ hide dropdown overlay on tapping anywhere else (especially menu) - ☐ add clear button to dropdown (or all text fields?) + ☐ improve dropdown component + ☐ account for deleted/disabled elements in dropdowns + ☐ hide dropdown overlay on tapping anywhere else (especially menu) + ☐ add clear button to dropdown (or all text fields?) ☐ check through all detail forms and set required fields/according messages - ☐ find a better way to work with multiple measurements (or disable it?) - ☐ evaluate if some fields should be readonly instead of completely hidden ☐ implement component for durations + ☐ order category lists (meals, meal sources,...) alphabetically + Basal/Bolus: + ☐ show daily Basal sum in overview + ☐ show KI and stuff for Bolus in overview + ☐ add save and close and next buttons on rate creations Log Overview: - ☐ add pagination ☐ apply target color settings to glucose Log Entry: - ☐ check if there is still an active bolus when suggesting glucose bolus + ☐ add save and close button + ☐ move on to newly created entry after saving + ☐ handle text overflow for log meal list + ☐ add option to specify trend for blood sugar + ☐ recalculate bolus upon deactivating 'set manually' option + ☐ account for delayed percentage setting on meals + Meal: + ☐ change delayed bolus rate to percentage + ☐ add meal source as subtitle in list Event Types: - ☐ add pagination ☐ add colors as indicators for log entries (and later graphs in reports) - ☐ implement reminders as push notifications Settings: + ☐ add setting for decimal places/unit steps ☐ add fields for preferred date and time formats ☐ add fields for glucose target (as map of cutoff glucose and colors) - ☐ add option to hide warning dialogs on cancel, delete or event stop - ☐ add option to hide extra customization options (ie. changing pre calculated values)? - ☐ add setting for decimal places ☐ add field for active insulin duration + ☐ add option to switch 'save' and 'save & close' buttons + +FUTURE TASKS: + General/Framework: + ☐ add explanations to each section + ☐ find a better way to work with multiple glucose measurements (or disable it?) + ☐ evaluate if some fields should be readonly instead of completely hidden + ☐ alternate languages + Reports: + ☐ evaluate what type of reports there should be + Basal/Bolus: + Log Overview: + ☐ add pagination + Log Entry: + ☐ check if there is still an active bolus when suggesting glucose bolus + Meal: + Event Types: + ☐ add pagination + ☐ implement reminders as push notifications + Settings: + ☐ add option to hide extra customization options (ie. changing pre calculated values)? Archive: + ✔ add option to hide warning dialogs on cancel, delete or event stop @done(21-12-05 19:18) @project(FUTURE TASKS.Settings) + ✔ fix settings saving @done(21-12-05 19:08) @project(MAIN TASKS.Settings) ✔ add objectbox settings class and use instead of shared preferences @done(21-12-05 00:41) @project(MAIN TASKS.Settings) ✔ provide percentage functionality for delayed bolus @done(21-12-04 21:39) @project(MAIN TASKS.Log Entry) ✔ create two bolus entries accordingly @done(21-12-04 22:12) @project(MAIN TASKS.Log Entry) diff --git a/lib/models/settings.dart b/lib/models/settings.dart index b7292cf..969cc25 100644 --- a/lib/models/settings.dart +++ b/lib/models/settings.dart @@ -44,9 +44,9 @@ class Settings { // properties int id; - NutritionMeasurement nutritionMeasurement; - GlucoseDisplayMode glucoseDisplayMode; - GlucoseMeasurement glucoseMeasurement; + int nutritionMeasurementIndex; + int glucoseDisplayModeIndex; + int glucoseMeasurementIndex; String dateFormat; String? longDateFormat; @@ -67,9 +67,9 @@ class Settings { // constructor Settings({ this.id = 0, - this.nutritionMeasurement = NutritionMeasurement.grams, - this.glucoseDisplayMode = GlucoseDisplayMode.bothForList, - this.glucoseMeasurement = GlucoseMeasurement.mgPerDl, + this.nutritionMeasurementIndex = 0, + this.glucoseDisplayModeIndex = 0, + this.glucoseMeasurementIndex = 0, this.dateFormat = 'MM/dd/yy', this.longDateFormat = 'MMMM dd, yyyy', this.timeFormat = 'HH:mm', @@ -86,8 +86,27 @@ class Settings { }); // methods - static Settings get() => box.getAll().single; + static Settings get() { + if (box.getAll().length != 1) { + reset(); + } + return box.getAll().single; + } + + static NutritionMeasurement get nutritionMeasurement => + NutritionMeasurement.values[get().nutritionMeasurementIndex]; + static GlucoseMeasurement get glucoseMeasurement => + GlucoseMeasurement.values[get().glucoseMeasurementIndex]; + static GlucoseDisplayMode get glucoseDisplayMode => + GlucoseDisplayMode.values[get().glucoseDisplayModeIndex]; + + static String get nutritionMeasurementSuffix => + nutritionMeasurementSuffixes[get().nutritionMeasurementIndex]; + static String get glucoseMeasurementSuffix => + glucoseMeasurementSuffixes[get().glucoseMeasurementIndex]; + static void put(Settings settings) => box.put(settings); + static void reset() { box.removeAll(); box.put(Settings()); diff --git a/lib/objectbox-model.json b/lib/objectbox-model.json index 1bd0e66..def03cc 100644 --- a/lib/objectbox-model.json +++ b/lib/objectbox-model.json @@ -794,7 +794,7 @@ }, { "id": "16:3989341091218179227", - "lastPropertyId": "14:3282706593658092097", + "lastPropertyId": "20:6560414475711071975", "name": "Settings", "properties": [ { @@ -867,6 +867,21 @@ "id": "14:3282706593658092097", "name": "highGlucoseMmolPerDl", "type": 8 + }, + { + "id": "18:1203593429961092769", + "name": "nutritionMeasurementIndex", + "type": 6 + }, + { + "id": "19:8895176254912253797", + "name": "glucoseDisplayModeIndex", + "type": 6 + }, + { + "id": "20:6560414475711071975", + "name": "glucoseMeasurementIndex", + "type": 6 } ], "relations": [] @@ -900,7 +915,10 @@ 3247926313599127440, 8789440370359282572, 7838546213550447420, - 8031421171668506924 + 8031421171668506924, + 1614362036318874174, + 1675040259141389754, + 7518219134349037920 ], "retiredRelationUids": [], "version": 1 diff --git a/lib/objectbox.g.dart b/lib/objectbox.g.dart index b9b2d43..507e5f7 100644 --- a/lib/objectbox.g.dart +++ b/lib/objectbox.g.dart @@ -794,7 +794,7 @@ final _entities = [ ModelEntity( id: const IdUid(16, 3989341091218179227), name: 'Settings', - lastPropertyId: const IdUid(14, 3282706593658092097), + lastPropertyId: const IdUid(20, 6560414475711071975), flags: 0, properties: [ ModelProperty( @@ -866,6 +866,21 @@ final _entities = [ id: const IdUid(14, 3282706593658092097), name: 'highGlucoseMmolPerDl', type: 8, + flags: 0), + ModelProperty( + id: const IdUid(18, 1203593429961092769), + name: 'nutritionMeasurementIndex', + type: 6, + flags: 0), + ModelProperty( + id: const IdUid(19, 8895176254912253797), + name: 'glucoseDisplayModeIndex', + type: 6, + flags: 0), + ModelProperty( + id: const IdUid(20, 6560414475711071975), + name: 'glucoseMeasurementIndex', + type: 6, flags: 0) ], relations: [], @@ -913,7 +928,10 @@ ModelDefinition getObjectBoxModel() { 3247926313599127440, 8789440370359282572, 7838546213550447420, - 8031421171668506924 + 8031421171668506924, + 1614362036318874174, + 1675040259141389754, + 7518219134349037920 ], retiredRelationUids: const [], modelVersion: 5, @@ -1644,7 +1662,7 @@ ModelDefinition getObjectBoxModel() { final longTimeFormatOffset = object.longTimeFormat == null ? null : fbb.writeString(object.longTimeFormat!); - fbb.startTable(15); + fbb.startTable(21); fbb.addInt64(0, object.id); fbb.addOffset(1, dateFormatOffset); fbb.addOffset(2, longDateFormatOffset); @@ -1659,6 +1677,9 @@ ModelDefinition getObjectBoxModel() { fbb.addFloat64(11, object.lowGlucoseMmolPerL); fbb.addFloat64(12, object.moderateGlucoseMmolPerL); fbb.addFloat64(13, object.highGlucoseMmolPerDl); + fbb.addInt64(17, object.nutritionMeasurementIndex); + fbb.addInt64(18, object.glucoseDisplayModeIndex); + fbb.addInt64(19, object.glucoseMeasurementIndex); fbb.finish(fbb.endTable()); return object.id; }, @@ -1668,6 +1689,12 @@ ModelDefinition getObjectBoxModel() { final object = Settings( id: const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0), + nutritionMeasurementIndex: + const fb.Int64Reader().vTableGet(buffer, rootOffset, 38, 0), + glucoseDisplayModeIndex: + const fb.Int64Reader().vTableGet(buffer, rootOffset, 40, 0), + glucoseMeasurementIndex: + const fb.Int64Reader().vTableGet(buffer, rootOffset, 42, 0), dateFormat: const fb.StringReader().vTableGet(buffer, rootOffset, 6, ''), longDateFormat: const fb.StringReader() @@ -1686,14 +1713,10 @@ ModelDefinition getObjectBoxModel() { const fb.Int64Reader().vTableGet(buffer, rootOffset, 20, 0), moderateGlucoseMgPerDl: const fb.Int64Reader().vTableGet(buffer, rootOffset, 22, 0), - highGlucoseMgPerDl: - const fb.Int64Reader().vTableGet(buffer, rootOffset, 24, 0), - lowGlucoseMmolPerL: - const fb.Float64Reader().vTableGet(buffer, rootOffset, 26, 0), - moderateGlucoseMmolPerL: - const fb.Float64Reader().vTableGet(buffer, rootOffset, 28, 0), - highGlucoseMmolPerDl: - const fb.Float64Reader().vTableGet(buffer, rootOffset, 30, 0)); + highGlucoseMgPerDl: const fb.Int64Reader().vTableGet(buffer, rootOffset, 24, 0), + lowGlucoseMmolPerL: const fb.Float64Reader().vTableGet(buffer, rootOffset, 26, 0), + moderateGlucoseMmolPerL: const fb.Float64Reader().vTableGet(buffer, rootOffset, 28, 0), + highGlucoseMmolPerDl: const fb.Float64Reader().vTableGet(buffer, rootOffset, 30, 0)); return object; }) @@ -2253,4 +2276,16 @@ class Settings_ { /// see [Settings.highGlucoseMmolPerDl] static final highGlucoseMmolPerDl = QueryDoubleProperty(_entities[14].properties[13]); + + /// see [Settings.nutritionMeasurementIndex] + static final nutritionMeasurementIndex = + QueryIntegerProperty(_entities[14].properties[14]); + + /// see [Settings.glucoseDisplayModeIndex] + static final glucoseDisplayModeIndex = + QueryIntegerProperty(_entities[14].properties[15]); + + /// see [Settings.glucoseMeasurementIndex] + static final glucoseMeasurementIndex = + QueryIntegerProperty(_entities[14].properties[16]); } diff --git a/lib/screens/bolus/bolus_detail.dart b/lib/screens/bolus/bolus_detail.dart index 69f2105..482f7a1 100644 --- a/lib/screens/bolus/bolus_detail.dart +++ b/lib/screens/bolus/bolus_detail.dart @@ -150,7 +150,7 @@ class _BolusDetailScreenState extends State { units: double.tryParse(_unitsController.text) ?? 0, carbs: double.tryParse(_carbsController.text) ?? 0, mgPerDl: int.tryParse(_mgPerDlController.text), - mmolPerL: double.parse(_mmolPerLController.text), + mmolPerL: double.tryParse(_mmolPerLController.text), ); bolus.bolusProfile.targetId = widget.bolusProfileId; Bolus.put(bolus); @@ -296,7 +296,7 @@ class _BolusDetailScreenState extends State { TextFormField( decoration: InputDecoration( labelText: 'per carbs', - suffixText: nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], + suffixText: Settings.nutritionMeasurementSuffix, ), controller: _carbsController, keyboardType: @@ -310,9 +310,9 @@ class _BolusDetailScreenState extends State { ), Row( children: [ - Settings.get().glucoseMeasurement == GlucoseMeasurement.mgPerDl || - Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == + Settings.glucoseMeasurement == GlucoseMeasurement.mgPerDl || + Settings.glucoseDisplayMode == GlucoseDisplayMode.both || + Settings.glucoseDisplayMode == GlucoseDisplayMode.bothForDetail ? Expanded( child: TextFormField( @@ -337,8 +337,8 @@ class _BolusDetailScreenState extends State { ), ) : Container(), - Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == + Settings.glucoseDisplayMode == GlucoseDisplayMode.both || + Settings.glucoseDisplayMode == GlucoseDisplayMode.bothForDetail ? IconButton( onPressed: () => convertBetweenMgPerDlAndMmolPerL( @@ -346,10 +346,8 @@ class _BolusDetailScreenState extends State { icon: const Icon(Icons.calculate), ) : Container(), - Settings.get().glucoseMeasurement == GlucoseMeasurement.mmolPerL || - Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.bothForDetail + Settings.glucoseMeasurement == GlucoseMeasurement.mmolPerL || + [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode) ? Expanded( child: TextFormField( decoration: const InputDecoration( @@ -374,9 +372,7 @@ class _BolusDetailScreenState extends State { ), ) : Container(), - Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.bothForDetail + [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode) ? IconButton( onPressed: () => convertBetweenMgPerDlAndMmolPerL( calculateFrom: GlucoseMeasurement.mgPerDl), diff --git a/lib/screens/bolus/bolus_list.dart b/lib/screens/bolus/bolus_list.dart index f8590af..c9c27fc 100644 --- a/lib/screens/bolus/bolus_list.dart +++ b/lib/screens/bolus/bolus_list.dart @@ -127,7 +127,7 @@ class _BolusListScreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - '${bolus.units} U per ${bolus.carbs}${nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index]} carbs/${Settings.get().glucoseMeasurement == GlucoseMeasurement.mgPerDl ? bolus.mgPerDl : bolus.mmolPerL} ${glucoseMeasurementSuffixes[Settings.get().glucoseMeasurement.index]}'), + '${bolus.units} U per ${bolus.carbs}${Settings.nutritionMeasurementSuffix} carbs/${Settings.glucoseMeasurement == GlucoseMeasurement.mgPerDl ? bolus.mgPerDl : bolus.mmolPerL} ${Settings.glucoseMeasurementSuffix}'), error != null ? Text(error, style: const TextStyle(color: Colors.red)) diff --git a/lib/screens/log/log.dart b/lib/screens/log/log.dart index 7cfe2cc..6979a51 100644 --- a/lib/screens/log/log.dart +++ b/lib/screens/log/log.dart @@ -109,11 +109,11 @@ class _LogScreenState extends State { Expanded( child: Column( children: logEntry.mgPerDl != null && - (Settings.get().glucoseMeasurement == + (Settings.glucoseMeasurement == GlucoseMeasurement.mgPerDl || - Settings.get().glucoseDisplayMode == + Settings.glucoseDisplayMode == GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == + Settings.glucoseDisplayMode == GlucoseDisplayMode .bothForList) ? [ @@ -129,11 +129,11 @@ class _LogScreenState extends State { Expanded( child: Column( children: logEntry.mmolPerL != null && - (Settings.get().glucoseMeasurement == + (Settings.glucoseMeasurement == GlucoseMeasurement.mmolPerL || - Settings.get().glucoseDisplayMode == + Settings.glucoseDisplayMode == GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == + Settings.glucoseDisplayMode == GlucoseDisplayMode .bothForList) ? [ @@ -163,7 +163,7 @@ class _LogScreenState extends State { ? [ Text(carbs.toStringAsPrecision(3)), Text( - nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], + Settings.nutritionMeasurementSuffix, textScaleFactor: 0.75), ] : [], diff --git a/lib/screens/log/log_entry/log_bolus_detail.dart b/lib/screens/log/log_entry/log_bolus_detail.dart index 77566e6..8d2b187 100644 --- a/lib/screens/log/log_entry/log_bolus_detail.dart +++ b/lib/screens/log/log_entry/log_bolus_detail.dart @@ -462,12 +462,8 @@ class _LogBolusDetailScreenState extends State { children: _bolusType == BolusType.glucose ? [ Row( - children: Settings.get().glucoseMeasurement == - GlucoseMeasurement.mgPerDl || - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.bothForDetail + children: Settings.glucoseMeasurement == GlucoseMeasurement.mgPerDl || + [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode) ? [ Expanded( child: Padding( @@ -520,10 +516,7 @@ class _LogBolusDetailScreenState extends State { ), ), ), - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.bothForDetail + [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode) ? IconButton( onPressed: () => onChangeGlucose( calculateFrom: @@ -536,12 +529,8 @@ class _LogBolusDetailScreenState extends State { : [], ), Row( - children: Settings.get().glucoseMeasurement == - GlucoseMeasurement.mmolPerL || - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.bothForDetail + children: Settings.glucoseMeasurement == GlucoseMeasurement.mmolPerL || + [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode) ? [ Expanded( child: Padding( @@ -595,10 +584,7 @@ class _LogBolusDetailScreenState extends State { ), ), ), - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.bothForDetail + [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode) ? IconButton( onPressed: () => onChangeGlucose( calculateFrom: @@ -624,7 +610,7 @@ class _LogBolusDetailScreenState extends State { TextFormField( decoration: InputDecoration( labelText: 'Carbs', - suffixText: nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], + suffixText: Settings.nutritionMeasurementSuffix, ), controller: _carbsController, onChanged: (_) => onChangeCarbs(), diff --git a/lib/screens/log/log_entry/log_bolus_list.dart b/lib/screens/log/log_entry/log_bolus_list.dart index b77c746..d23b480 100644 --- a/lib/screens/log/log_entry/log_bolus_list.dart +++ b/lib/screens/log/log_entry/log_bolus_list.dart @@ -98,8 +98,8 @@ class _LogBolusListScreenState extends State { onTap: () => handleEditAction(bolus), title: Text(titleText), subtitle: Text(bolus.carbs != null ? - 'for ${bolus.meal.target.toString()} (${bolus.carbs}${nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index]} carbs)' - : 'to correct ${Settings.get().glucoseMeasurement == GlucoseMeasurement.mgPerDl ? bolus.mgPerDlCorrection : bolus.mmolPerLCorrection} ${glucoseMeasurementSuffixes[Settings.get().glucoseMeasurement.index]}'), + 'for ${bolus.meal.target.toString()} (${bolus.carbs}${Settings.nutritionMeasurementSuffix} carbs)' + : 'to correct ${Settings.glucoseMeasurement == GlucoseMeasurement.mgPerDl ? bolus.mgPerDlCorrection : bolus.mmolPerLCorrection} ${Settings.glucoseMeasurementSuffix}'), trailing: Row( mainAxisSize: MainAxisSize.min, children: [ diff --git a/lib/screens/log/log_entry/log_entry.dart b/lib/screens/log/log_entry/log_entry.dart index 3cb55e3..9f07b91 100644 --- a/lib/screens/log/log_entry/log_entry.dart +++ b/lib/screens/log/log_entry/log_entry.dart @@ -310,11 +310,8 @@ class _LogEntryScreenState extends State { ), Row( children: [ - Settings.get().glucoseMeasurement == GlucoseMeasurement.mgPerDl || - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == - GlucoseDisplayMode.bothForDetail + Settings.glucoseMeasurement == GlucoseMeasurement.mgPerDl || + [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode) ? Expanded( child: TextFormField( decoration: const InputDecoration( @@ -340,8 +337,8 @@ class _LogEntryScreenState extends State { ), ) : Container(), - Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == + Settings.glucoseDisplayMode == GlucoseDisplayMode.both || + Settings.glucoseDisplayMode == GlucoseDisplayMode.bothForDetail ? IconButton( onPressed: () => @@ -351,10 +348,10 @@ class _LogEntryScreenState extends State { icon: const Icon(Icons.calculate), ) : Container(), - Settings.get().glucoseMeasurement == GlucoseMeasurement.mmolPerL || - Settings.get().glucoseDisplayMode == + Settings.glucoseMeasurement == GlucoseMeasurement.mmolPerL || + Settings.glucoseDisplayMode == GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == + Settings.glucoseDisplayMode == GlucoseDisplayMode.bothForDetail ? Expanded( child: TextFormField( @@ -382,8 +379,8 @@ class _LogEntryScreenState extends State { ), ) : Container(), - Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || - Settings.get().glucoseDisplayMode == + Settings.glucoseDisplayMode == GlucoseDisplayMode.both || + Settings.glucoseDisplayMode == GlucoseDisplayMode.bothForDetail ? IconButton( onPressed: () => diff --git a/lib/screens/log/log_entry/log_meal_detail.dart b/lib/screens/log/log_entry/log_meal_detail.dart index fbc1441..6e037b4 100644 --- a/lib/screens/log/log_entry/log_meal_detail.dart +++ b/lib/screens/log/log_entry/log_meal_detail.dart @@ -324,7 +324,7 @@ class _LogMealDetailScreenState extends State { decoration: InputDecoration( labelText: 'Portion size', suffixText: - nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], + Settings.nutritionMeasurementSuffix, alignLabelWithHint: true, ), controller: _portionSizeController, @@ -360,7 +360,7 @@ class _LogMealDetailScreenState extends State { decoration: InputDecoration( labelText: 'Carbs per portion', suffixText: - nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], + Settings.nutritionMeasurementSuffix, ), controller: _carbsPerPortionController, keyboardType: const TextInputType.numberWithOptions( diff --git a/lib/screens/meal/meal_detail.dart b/lib/screens/meal/meal_detail.dart index bcc96e3..8520364 100644 --- a/lib/screens/meal/meal_detail.dart +++ b/lib/screens/meal/meal_detail.dart @@ -312,7 +312,7 @@ class _MealDetailScreenState extends State { decoration: InputDecoration( labelText: 'Portion size', suffixText: - nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], + Settings.nutritionMeasurementSuffix, alignLabelWithHint: true, ), controller: _portionSizeController, @@ -348,7 +348,7 @@ class _MealDetailScreenState extends State { decoration: InputDecoration( labelText: 'Carbs per portion', suffixText: - nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], + Settings.nutritionMeasurementSuffix, ), controller: _carbsPerPortionController, keyboardType: const TextInputType.numberWithOptions( diff --git a/lib/settings.dart b/lib/settings.dart index 3544fb1..3c58cde 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -17,43 +17,58 @@ class SettingsScreen extends StatefulWidget { class _SettingsScreenState extends State { late Settings _settings; + late String _nutritionMeasurementLabel; + late String _glucoseMeasurementLabel; + late bool _onlyDisplayActiveGlucoseMeasurement; late bool _displayBothGlucoseMeasurementsInDetailView; late bool _displayBothGlucoseMeasurementsInListView; + // late String _dateFormat; + // late String? _longDateFormat; + // late String _timeFormat; + // late String? _longTimeFormat; + + late bool _showConfirmationDialogOnCancel; + late bool _showConfirmationDialogOnDelete; + late bool _showConfirmationDialogOnStopEvent; + + // late int _lowGlucoseMgPerDl; + // late int _moderateGlucoseMgPerDl; + // late int _highGlucoseMgPerDl; + // late double _lowGlucoseMmolPerL; + // late double _moderateGlucoseMmolPerL; + // late double _highGlucoseMmolPerDl; + @override void initState() { super.initState(); - reload(); - } - - void onReset() { - Settings.reset(); - reload(message: 'Settings have been reset to default'); - } - - void saveSettings() { - Settings.put(Settings( - id: _settings.id, - nutritionMeasurement: _settings.nutritionMeasurement, - glucoseDisplayMode: _settings.glucoseDisplayMode, - glucoseMeasurement: _settings.glucoseMeasurement, - dateFormat: _settings.dateFormat, - longDateFormat: _settings.longDateFormat, - timeFormat: _settings.timeFormat, - longTimeFormat: _settings.longTimeFormat, - showConfirmationDialogOnCancel: _settings.showConfirmationDialogOnCancel, - showConfirmationDialogOnDelete: _settings.showConfirmationDialogOnDelete, - showConfirmationDialogOnStopEvent: - _settings.showConfirmationDialogOnStopEvent, - lowGlucoseMgPerDl: _settings.lowGlucoseMgPerDl, - moderateGlucoseMgPerDl: _settings.moderateGlucoseMgPerDl, - highGlucoseMgPerDl: _settings.highGlucoseMgPerDl, - lowGlucoseMmolPerL: _settings.lowGlucoseMmolPerL, - moderateGlucoseMmolPerL: _settings.moderateGlucoseMmolPerL, - highGlucoseMmolPerDl: _settings.highGlucoseMmolPerDl, - )); - reload(message: 'Settings updated'); + _settings = Settings.get(); + _nutritionMeasurementLabel = + nutritionMeasurementLabels[_settings.nutritionMeasurementIndex]; + _glucoseMeasurementLabel = + glucoseMeasurementLabels[_settings.glucoseMeasurementIndex]; + _onlyDisplayActiveGlucoseMeasurement = _settings.glucoseDisplayModeIndex == GlucoseDisplayMode.activeOnly.index; + _displayBothGlucoseMeasurementsInDetailView = + _settings.glucoseDisplayModeIndex == GlucoseDisplayMode.both.index || + _settings.glucoseDisplayModeIndex == GlucoseDisplayMode.bothForDetail.index; + _displayBothGlucoseMeasurementsInListView = + _settings.glucoseDisplayModeIndex == GlucoseDisplayMode.both.index || + _settings.glucoseDisplayModeIndex == GlucoseDisplayMode.bothForList.index; + // _dateFormat = _settings.dateFormat; + // _longDateFormat = _settings.longDateFormat; + // _timeFormat = _settings.timeFormat; + // _longTimeFormat = _settings.longTimeFormat; + _showConfirmationDialogOnCancel = _settings.showConfirmationDialogOnCancel; + _showConfirmationDialogOnDelete = _settings.showConfirmationDialogOnDelete; + _showConfirmationDialogOnStopEvent = + _settings.showConfirmationDialogOnStopEvent; + // _lowGlucoseMgPerDl = _settings.lowGlucoseMgPerDl; + // _moderateGlucoseMgPerDl = _settings.moderateGlucoseMgPerDl; + // _highGlucoseMgPerDl = _settings.highGlucoseMgPerDl; + // _lowGlucoseMmolPerL = _settings.lowGlucoseMmolPerL; + // _moderateGlucoseMmolPerL = _settings.moderateGlucoseMmolPerL; + // _highGlucoseMmolPerDl = _settings.highGlucoseMmolPerDl; } void reload({String? message}) { @@ -61,17 +76,6 @@ class _SettingsScreenState extends State { _settings = Settings.get(); }); - setState(() { - _onlyDisplayActiveGlucoseMeasurement = - _settings.glucoseDisplayMode == GlucoseDisplayMode.activeOnly; - _displayBothGlucoseMeasurementsInDetailView = - _settings.glucoseDisplayMode == GlucoseDisplayMode.both || - _settings.glucoseDisplayMode == GlucoseDisplayMode.bothForDetail; - _displayBothGlucoseMeasurementsInListView = - _settings.glucoseDisplayMode == GlucoseDisplayMode.both || - _settings.glucoseDisplayMode == GlucoseDisplayMode.bothForList; - }); - setState(() { if (message != null) { var snackBar = SnackBar( @@ -85,6 +89,54 @@ class _SettingsScreenState extends State { }); } + void saveSettings() { + Settings.put(Settings( + id: _settings.id, + nutritionMeasurementIndex: + nutritionMeasurementLabels.indexOf(_nutritionMeasurementLabel), + glucoseMeasurementIndex: + glucoseMeasurementLabels.indexOf(_glucoseMeasurementLabel), + glucoseDisplayModeIndex: _onlyDisplayActiveGlucoseMeasurement + ? GlucoseDisplayMode.activeOnly.index + : _displayBothGlucoseMeasurementsInDetailView && _displayBothGlucoseMeasurementsInListView + ? GlucoseDisplayMode.both.index + : _displayBothGlucoseMeasurementsInDetailView + ? GlucoseDisplayMode.bothForDetail.index + : GlucoseDisplayMode.bothForList.index, + // dateFormat: _dateFormat, + // longDateFormat: _longDateFormat, + // timeFormat: _timeFormat, + // longTimeFormat: _longTimeFormat, + // showConfirmationDialogOnCancel: _showConfirmationDialogOnCancel, + // showConfirmationDialogOnDelete: _showConfirmationDialogOnDelete, + // showConfirmationDialogOnStopEvent: _showConfirmationDialogOnStopEvent, + // lowGlucoseMgPerDl: _dateFormat: _dateFormat, + // longDateFormat: _longDateFormat, + // timeFormat: _timeFormat, + // longTimeFormat: _longTimeFormat, + showConfirmationDialogOnCancel: _showConfirmationDialogOnCancel, + showConfirmationDialogOnDelete: _showConfirmationDialogOnDelete, + showConfirmationDialogOnStopEvent: _showConfirmationDialogOnStopEvent, + // lowGlucoseMgPerDl: _lowGlucoseMgPerDl, + // moderateGlucoseMgPerDl: _moderateGlucoseMgPerDl, + // highGlucoseMgPerDl: _highGlucoseMgPerDl, + // lowGlucoseMmolPerL: _lowGlucoseMmolPerL, + // moderateGlucoseMmolPerL: _moderateGlucoseMmolPerL, + // highGlucoseMmolPerDl: _highGlucoseMmolPerDl,lowGlucoseMgPerDl, + // moderateGlucoseMgPerDl: _moderateGlucoseMgPerDl, + // highGlucoseMgPerDl: _highGlucoseMgPerDl, + // lowGlucoseMmolPerL: _lowGlucoseMmolPerL, + // moderateGlucoseMmolPerL: _moderateGlucoseMmolPerL, + // highGlucoseMmolPerDl: _highGlucoseMmolPerDl, + )); + reload(message: 'Settings updated'); + } + + void onReset() { + Settings.reset(); + reload(message: 'Settings have been reset to default'); + } + void handleResetAction() async { Dialogs.showConfirmationDialog( context: context, @@ -101,30 +153,28 @@ class _SettingsScreenState extends State { ), drawer: const Navigation(currentLocation: SettingsScreen.routeName), body: SingleChildScrollView( + padding: const EdgeInsets.all(10.0), child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ AutoCompleteDropdownButton( - selectedItem: nutritionMeasurementLabels[ - _settings.nutritionMeasurement.index], + selectedItem: _nutritionMeasurementLabel, label: 'Preferred Nutrition Measurement', items: nutritionMeasurementLabels, onChanged: (value) { if (value != null) { - _settings.nutritionMeasurement = NutritionMeasurement.values - .elementAt(nutritionMeasurementLabels.indexOf(value)); + _nutritionMeasurementLabel = value; saveSettings(); } }, ), AutoCompleteDropdownButton( - selectedItem: - glucoseMeasurementLabels[_settings.glucoseMeasurement.index], + selectedItem: _glucoseMeasurementLabel, label: 'Preferred Glucose Measurement', items: glucoseMeasurementLabels, onChanged: (value) { if (value != null) { - _settings.glucoseMeasurement = GlucoseMeasurement.values - .elementAt(glucoseMeasurementLabels.indexOf(value)); + _glucoseMeasurementLabel = value; saveSettings(); } }, @@ -132,46 +182,54 @@ class _SettingsScreenState extends State { BooleanFormField( value: _onlyDisplayActiveGlucoseMeasurement, label: 'only display active glucose measurement', - onChanged: (_) { - GlucoseDisplayMode mode = _settings.glucoseDisplayMode == - GlucoseDisplayMode.activeOnly - ? GlucoseDisplayMode.both - : GlucoseDisplayMode.activeOnly; - _settings.glucoseDisplayMode = mode; + onChanged: (value) { + _onlyDisplayActiveGlucoseMeasurement = value; saveSettings(); }, ), BooleanFormField( value: _displayBothGlucoseMeasurementsInDetailView, - enabled: - !_onlyDisplayActiveGlucoseMeasurement, + enabled: !_onlyDisplayActiveGlucoseMeasurement, label: 'display both glucose measurements in detail view', - onChanged: (_) { - GlucoseDisplayMode mode = - _settings.glucoseDisplayMode == GlucoseDisplayMode.both - ? GlucoseDisplayMode.bothForList - : _settings.glucoseDisplayMode == - GlucoseDisplayMode.bothForList - ? GlucoseDisplayMode.both - : GlucoseDisplayMode.activeOnly; - _settings.glucoseDisplayMode = mode; + onChanged: (value) { + _displayBothGlucoseMeasurementsInDetailView = value; saveSettings(); }, ), BooleanFormField( value: _displayBothGlucoseMeasurementsInListView, - enabled: - !_onlyDisplayActiveGlucoseMeasurement, + enabled: !_onlyDisplayActiveGlucoseMeasurement, label: 'display both glucose measurements in list view', - onChanged: (_) { - GlucoseDisplayMode mode = - _settings.glucoseDisplayMode == GlucoseDisplayMode.both - ? GlucoseDisplayMode.bothForDetail - : _settings.glucoseDisplayMode == - GlucoseDisplayMode.bothForDetail - ? GlucoseDisplayMode.both - : GlucoseDisplayMode.activeOnly; - _settings.glucoseDisplayMode = mode; + onChanged: (value) { + _displayBothGlucoseMeasurementsInListView = value; + saveSettings(); + }, + ), + const Padding( + padding: EdgeInsets.only(top: 10.0), + child: Text('Confirmation prompts'), + ), + BooleanFormField( + value: _showConfirmationDialogOnCancel, + label: 'on cancelling edit or creation of a record if changes have already been made', + onChanged: (value) { + _showConfirmationDialogOnCancel = value; + saveSettings(); + }, + ), + BooleanFormField( + value: _showConfirmationDialogOnDelete, + label: 'on deleting a record', + onChanged: (value) { + _showConfirmationDialogOnDelete = value; + saveSettings(); + }, + ), + BooleanFormField( + value: _showConfirmationDialogOnStopEvent, + label: 'on stopping (ending) an event', + onChanged: (value) { + _showConfirmationDialogOnStopEvent = value; saveSettings(); }, ),