fix settings, reevaluate todo list

This commit is contained in:
spinel 2021-12-06 01:11:22 +01:00
parent a59170940f
commit 9892d7870f
13 changed files with 320 additions and 175 deletions

70
TODO
View File

@ -1,38 +1,74 @@
MAIN TASKS: BUGFIXES:
Settings: General/Framework:
☐ fix settings saving ☐ 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: General/Framework:
☐ show indicator and make all fields readonly if user somehow gets to a deleted record detail view ☐ 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) ☐ add functionality to delete dead records (meaning: set deleted flag and no relations)
☐ clean up controllers (dispose method of each stateful widget) ☐ clean up controllers (dispose method of each stateful widget)
add explanations to each section improve dropdown component
☐ account for deleted/disabled elements in dropdowns ☐ account for deleted/disabled elements in dropdowns
☐ hide dropdown overlay on tapping anywhere else (especially menu) ☐ hide dropdown overlay on tapping anywhere else (especially menu)
☐ add clear button to dropdown (or all text fields?) ☐ add clear button to dropdown (or all text fields?)
☐ check through all detail forms and set required fields/according messages ☐ 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 ☐ 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: Log Overview:
☐ add pagination
☐ apply target color settings to glucose ☐ apply target color settings to glucose
Log Entry: 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: Event Types:
☐ add pagination
☐ add colors as indicators for log entries (and later graphs in reports) ☐ add colors as indicators for log entries (and later graphs in reports)
☐ implement reminders as push notifications
Settings: Settings:
☐ add setting for decimal places/unit steps
☐ add fields for preferred date and time formats ☐ add fields for preferred date and time formats
☐ add fields for glucose target (as map of cutoff glucose and colors) ☐ 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 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: 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) ✔ 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) ✔ 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) ✔ create two bolus entries accordingly @done(21-12-04 22:12) @project(MAIN TASKS.Log Entry)

View File

@ -44,9 +44,9 @@ class Settings {
// properties // properties
int id; int id;
NutritionMeasurement nutritionMeasurement; int nutritionMeasurementIndex;
GlucoseDisplayMode glucoseDisplayMode; int glucoseDisplayModeIndex;
GlucoseMeasurement glucoseMeasurement; int glucoseMeasurementIndex;
String dateFormat; String dateFormat;
String? longDateFormat; String? longDateFormat;
@ -67,9 +67,9 @@ class Settings {
// constructor // constructor
Settings({ Settings({
this.id = 0, this.id = 0,
this.nutritionMeasurement = NutritionMeasurement.grams, this.nutritionMeasurementIndex = 0,
this.glucoseDisplayMode = GlucoseDisplayMode.bothForList, this.glucoseDisplayModeIndex = 0,
this.glucoseMeasurement = GlucoseMeasurement.mgPerDl, this.glucoseMeasurementIndex = 0,
this.dateFormat = 'MM/dd/yy', this.dateFormat = 'MM/dd/yy',
this.longDateFormat = 'MMMM dd, yyyy', this.longDateFormat = 'MMMM dd, yyyy',
this.timeFormat = 'HH:mm', this.timeFormat = 'HH:mm',
@ -86,8 +86,27 @@ class Settings {
}); });
// methods // 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 put(Settings settings) => box.put(settings);
static void reset() { static void reset() {
box.removeAll(); box.removeAll();
box.put(Settings()); box.put(Settings());

View File

@ -794,7 +794,7 @@
}, },
{ {
"id": "16:3989341091218179227", "id": "16:3989341091218179227",
"lastPropertyId": "14:3282706593658092097", "lastPropertyId": "20:6560414475711071975",
"name": "Settings", "name": "Settings",
"properties": [ "properties": [
{ {
@ -867,6 +867,21 @@
"id": "14:3282706593658092097", "id": "14:3282706593658092097",
"name": "highGlucoseMmolPerDl", "name": "highGlucoseMmolPerDl",
"type": 8 "type": 8
},
{
"id": "18:1203593429961092769",
"name": "nutritionMeasurementIndex",
"type": 6
},
{
"id": "19:8895176254912253797",
"name": "glucoseDisplayModeIndex",
"type": 6
},
{
"id": "20:6560414475711071975",
"name": "glucoseMeasurementIndex",
"type": 6
} }
], ],
"relations": [] "relations": []
@ -900,7 +915,10 @@
3247926313599127440, 3247926313599127440,
8789440370359282572, 8789440370359282572,
7838546213550447420, 7838546213550447420,
8031421171668506924 8031421171668506924,
1614362036318874174,
1675040259141389754,
7518219134349037920
], ],
"retiredRelationUids": [], "retiredRelationUids": [],
"version": 1 "version": 1

View File

@ -794,7 +794,7 @@ final _entities = <ModelEntity>[
ModelEntity( ModelEntity(
id: const IdUid(16, 3989341091218179227), id: const IdUid(16, 3989341091218179227),
name: 'Settings', name: 'Settings',
lastPropertyId: const IdUid(14, 3282706593658092097), lastPropertyId: const IdUid(20, 6560414475711071975),
flags: 0, flags: 0,
properties: <ModelProperty>[ properties: <ModelProperty>[
ModelProperty( ModelProperty(
@ -866,6 +866,21 @@ final _entities = <ModelEntity>[
id: const IdUid(14, 3282706593658092097), id: const IdUid(14, 3282706593658092097),
name: 'highGlucoseMmolPerDl', name: 'highGlucoseMmolPerDl',
type: 8, 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) flags: 0)
], ],
relations: <ModelRelation>[], relations: <ModelRelation>[],
@ -913,7 +928,10 @@ ModelDefinition getObjectBoxModel() {
3247926313599127440, 3247926313599127440,
8789440370359282572, 8789440370359282572,
7838546213550447420, 7838546213550447420,
8031421171668506924 8031421171668506924,
1614362036318874174,
1675040259141389754,
7518219134349037920
], ],
retiredRelationUids: const [], retiredRelationUids: const [],
modelVersion: 5, modelVersion: 5,
@ -1644,7 +1662,7 @@ ModelDefinition getObjectBoxModel() {
final longTimeFormatOffset = object.longTimeFormat == null final longTimeFormatOffset = object.longTimeFormat == null
? null ? null
: fbb.writeString(object.longTimeFormat!); : fbb.writeString(object.longTimeFormat!);
fbb.startTable(15); fbb.startTable(21);
fbb.addInt64(0, object.id); fbb.addInt64(0, object.id);
fbb.addOffset(1, dateFormatOffset); fbb.addOffset(1, dateFormatOffset);
fbb.addOffset(2, longDateFormatOffset); fbb.addOffset(2, longDateFormatOffset);
@ -1659,6 +1677,9 @@ ModelDefinition getObjectBoxModel() {
fbb.addFloat64(11, object.lowGlucoseMmolPerL); fbb.addFloat64(11, object.lowGlucoseMmolPerL);
fbb.addFloat64(12, object.moderateGlucoseMmolPerL); fbb.addFloat64(12, object.moderateGlucoseMmolPerL);
fbb.addFloat64(13, object.highGlucoseMmolPerDl); fbb.addFloat64(13, object.highGlucoseMmolPerDl);
fbb.addInt64(17, object.nutritionMeasurementIndex);
fbb.addInt64(18, object.glucoseDisplayModeIndex);
fbb.addInt64(19, object.glucoseMeasurementIndex);
fbb.finish(fbb.endTable()); fbb.finish(fbb.endTable());
return object.id; return object.id;
}, },
@ -1668,6 +1689,12 @@ ModelDefinition getObjectBoxModel() {
final object = Settings( final object = Settings(
id: const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0), 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: dateFormat:
const fb.StringReader().vTableGet(buffer, rootOffset, 6, ''), const fb.StringReader().vTableGet(buffer, rootOffset, 6, ''),
longDateFormat: const fb.StringReader() longDateFormat: const fb.StringReader()
@ -1686,14 +1713,10 @@ ModelDefinition getObjectBoxModel() {
const fb.Int64Reader().vTableGet(buffer, rootOffset, 20, 0), const fb.Int64Reader().vTableGet(buffer, rootOffset, 20, 0),
moderateGlucoseMgPerDl: moderateGlucoseMgPerDl:
const fb.Int64Reader().vTableGet(buffer, rootOffset, 22, 0), const fb.Int64Reader().vTableGet(buffer, rootOffset, 22, 0),
highGlucoseMgPerDl: highGlucoseMgPerDl: const fb.Int64Reader().vTableGet(buffer, rootOffset, 24, 0),
const fb.Int64Reader().vTableGet(buffer, rootOffset, 24, 0), lowGlucoseMmolPerL: const fb.Float64Reader().vTableGet(buffer, rootOffset, 26, 0),
lowGlucoseMmolPerL: moderateGlucoseMmolPerL: const fb.Float64Reader().vTableGet(buffer, rootOffset, 28, 0),
const fb.Float64Reader().vTableGet(buffer, rootOffset, 26, 0), highGlucoseMmolPerDl: const fb.Float64Reader().vTableGet(buffer, rootOffset, 30, 0));
moderateGlucoseMmolPerL:
const fb.Float64Reader().vTableGet(buffer, rootOffset, 28, 0),
highGlucoseMmolPerDl:
const fb.Float64Reader().vTableGet(buffer, rootOffset, 30, 0));
return object; return object;
}) })
@ -2253,4 +2276,16 @@ class Settings_ {
/// see [Settings.highGlucoseMmolPerDl] /// see [Settings.highGlucoseMmolPerDl]
static final highGlucoseMmolPerDl = static final highGlucoseMmolPerDl =
QueryDoubleProperty<Settings>(_entities[14].properties[13]); QueryDoubleProperty<Settings>(_entities[14].properties[13]);
/// see [Settings.nutritionMeasurementIndex]
static final nutritionMeasurementIndex =
QueryIntegerProperty<Settings>(_entities[14].properties[14]);
/// see [Settings.glucoseDisplayModeIndex]
static final glucoseDisplayModeIndex =
QueryIntegerProperty<Settings>(_entities[14].properties[15]);
/// see [Settings.glucoseMeasurementIndex]
static final glucoseMeasurementIndex =
QueryIntegerProperty<Settings>(_entities[14].properties[16]);
} }

View File

@ -150,7 +150,7 @@ class _BolusDetailScreenState extends State<BolusDetailScreen> {
units: double.tryParse(_unitsController.text) ?? 0, units: double.tryParse(_unitsController.text) ?? 0,
carbs: double.tryParse(_carbsController.text) ?? 0, carbs: double.tryParse(_carbsController.text) ?? 0,
mgPerDl: int.tryParse(_mgPerDlController.text), mgPerDl: int.tryParse(_mgPerDlController.text),
mmolPerL: double.parse(_mmolPerLController.text), mmolPerL: double.tryParse(_mmolPerLController.text),
); );
bolus.bolusProfile.targetId = widget.bolusProfileId; bolus.bolusProfile.targetId = widget.bolusProfileId;
Bolus.put(bolus); Bolus.put(bolus);
@ -296,7 +296,7 @@ class _BolusDetailScreenState extends State<BolusDetailScreen> {
TextFormField( TextFormField(
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'per carbs', labelText: 'per carbs',
suffixText: nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], suffixText: Settings.nutritionMeasurementSuffix,
), ),
controller: _carbsController, controller: _carbsController,
keyboardType: keyboardType:
@ -310,9 +310,9 @@ class _BolusDetailScreenState extends State<BolusDetailScreen> {
), ),
Row( Row(
children: [ children: [
Settings.get().glucoseMeasurement == GlucoseMeasurement.mgPerDl || Settings.glucoseMeasurement == GlucoseMeasurement.mgPerDl ||
Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || Settings.glucoseDisplayMode == GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode == Settings.glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail GlucoseDisplayMode.bothForDetail
? Expanded( ? Expanded(
child: TextFormField( child: TextFormField(
@ -337,8 +337,8 @@ class _BolusDetailScreenState extends State<BolusDetailScreen> {
), ),
) )
: Container(), : Container(),
Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || Settings.glucoseDisplayMode == GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode == Settings.glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail GlucoseDisplayMode.bothForDetail
? IconButton( ? IconButton(
onPressed: () => convertBetweenMgPerDlAndMmolPerL( onPressed: () => convertBetweenMgPerDlAndMmolPerL(
@ -346,10 +346,8 @@ class _BolusDetailScreenState extends State<BolusDetailScreen> {
icon: const Icon(Icons.calculate), icon: const Icon(Icons.calculate),
) )
: Container(), : Container(),
Settings.get().glucoseMeasurement == GlucoseMeasurement.mmolPerL || Settings.glucoseMeasurement == GlucoseMeasurement.mmolPerL ||
Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode)
Settings.get().glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail
? Expanded( ? Expanded(
child: TextFormField( child: TextFormField(
decoration: const InputDecoration( decoration: const InputDecoration(
@ -374,9 +372,7 @@ class _BolusDetailScreenState extends State<BolusDetailScreen> {
), ),
) )
: Container(), : Container(),
Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode)
Settings.get().glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail
? IconButton( ? IconButton(
onPressed: () => convertBetweenMgPerDlAndMmolPerL( onPressed: () => convertBetweenMgPerDlAndMmolPerL(
calculateFrom: GlucoseMeasurement.mgPerDl), calculateFrom: GlucoseMeasurement.mgPerDl),

View File

@ -127,7 +127,7 @@ class _BolusListScreenState extends State<BolusListScreen> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( 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 error != null
? Text(error, ? Text(error,
style: const TextStyle(color: Colors.red)) style: const TextStyle(color: Colors.red))

View File

@ -109,11 +109,11 @@ class _LogScreenState extends State<LogScreen> {
Expanded( Expanded(
child: Column( child: Column(
children: logEntry.mgPerDl != null && children: logEntry.mgPerDl != null &&
(Settings.get().glucoseMeasurement == (Settings.glucoseMeasurement ==
GlucoseMeasurement.mgPerDl || GlucoseMeasurement.mgPerDl ||
Settings.get().glucoseDisplayMode == Settings.glucoseDisplayMode ==
GlucoseDisplayMode.both || GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode == Settings.glucoseDisplayMode ==
GlucoseDisplayMode GlucoseDisplayMode
.bothForList) .bothForList)
? [ ? [
@ -129,11 +129,11 @@ class _LogScreenState extends State<LogScreen> {
Expanded( Expanded(
child: Column( child: Column(
children: logEntry.mmolPerL != null && children: logEntry.mmolPerL != null &&
(Settings.get().glucoseMeasurement == (Settings.glucoseMeasurement ==
GlucoseMeasurement.mmolPerL || GlucoseMeasurement.mmolPerL ||
Settings.get().glucoseDisplayMode == Settings.glucoseDisplayMode ==
GlucoseDisplayMode.both || GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode == Settings.glucoseDisplayMode ==
GlucoseDisplayMode GlucoseDisplayMode
.bothForList) .bothForList)
? [ ? [
@ -163,7 +163,7 @@ class _LogScreenState extends State<LogScreen> {
? [ ? [
Text(carbs.toStringAsPrecision(3)), Text(carbs.toStringAsPrecision(3)),
Text( Text(
nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], Settings.nutritionMeasurementSuffix,
textScaleFactor: 0.75), textScaleFactor: 0.75),
] ]
: [], : [],

View File

@ -462,12 +462,8 @@ class _LogBolusDetailScreenState extends State<LogBolusDetailScreen> {
children: _bolusType == BolusType.glucose children: _bolusType == BolusType.glucose
? [ ? [
Row( Row(
children: Settings.get().glucoseMeasurement == children: Settings.glucoseMeasurement == GlucoseMeasurement.mgPerDl ||
GlucoseMeasurement.mgPerDl || [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode)
Settings.get().glucoseDisplayMode ==
GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail
? [ ? [
Expanded( Expanded(
child: Padding( child: Padding(
@ -520,10 +516,7 @@ class _LogBolusDetailScreenState extends State<LogBolusDetailScreen> {
), ),
), ),
), ),
Settings.get().glucoseDisplayMode == [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode)
GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail
? IconButton( ? IconButton(
onPressed: () => onChangeGlucose( onPressed: () => onChangeGlucose(
calculateFrom: calculateFrom:
@ -536,12 +529,8 @@ class _LogBolusDetailScreenState extends State<LogBolusDetailScreen> {
: [], : [],
), ),
Row( Row(
children: Settings.get().glucoseMeasurement == children: Settings.glucoseMeasurement == GlucoseMeasurement.mmolPerL ||
GlucoseMeasurement.mmolPerL || [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode)
Settings.get().glucoseDisplayMode ==
GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail
? [ ? [
Expanded( Expanded(
child: Padding( child: Padding(
@ -595,10 +584,7 @@ class _LogBolusDetailScreenState extends State<LogBolusDetailScreen> {
), ),
), ),
), ),
Settings.get().glucoseDisplayMode == [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode)
GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail
? IconButton( ? IconButton(
onPressed: () => onChangeGlucose( onPressed: () => onChangeGlucose(
calculateFrom: calculateFrom:
@ -624,7 +610,7 @@ class _LogBolusDetailScreenState extends State<LogBolusDetailScreen> {
TextFormField( TextFormField(
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Carbs', labelText: 'Carbs',
suffixText: nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], suffixText: Settings.nutritionMeasurementSuffix,
), ),
controller: _carbsController, controller: _carbsController,
onChanged: (_) => onChangeCarbs(), onChanged: (_) => onChangeCarbs(),

View File

@ -98,8 +98,8 @@ class _LogBolusListScreenState extends State<LogBolusListScreen> {
onTap: () => handleEditAction(bolus), onTap: () => handleEditAction(bolus),
title: Text(titleText), title: Text(titleText),
subtitle: Text(bolus.carbs != null ? subtitle: Text(bolus.carbs != null ?
'for ${bolus.meal.target.toString()} (${bolus.carbs}${nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index]} carbs)' 'for ${bolus.meal.target.toString()} (${bolus.carbs}${Settings.nutritionMeasurementSuffix} carbs)'
: 'to correct ${Settings.get().glucoseMeasurement == GlucoseMeasurement.mgPerDl ? bolus.mgPerDlCorrection : bolus.mmolPerLCorrection} ${glucoseMeasurementSuffixes[Settings.get().glucoseMeasurement.index]}'), : 'to correct ${Settings.glucoseMeasurement == GlucoseMeasurement.mgPerDl ? bolus.mgPerDlCorrection : bolus.mmolPerLCorrection} ${Settings.glucoseMeasurementSuffix}'),
trailing: Row( trailing: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [

View File

@ -310,11 +310,8 @@ class _LogEntryScreenState extends State<LogEntryScreen> {
), ),
Row( Row(
children: [ children: [
Settings.get().glucoseMeasurement == GlucoseMeasurement.mgPerDl || Settings.glucoseMeasurement == GlucoseMeasurement.mgPerDl ||
Settings.get().glucoseDisplayMode == [GlucoseDisplayMode.both, GlucoseDisplayMode.bothForDetail].contains(Settings.glucoseDisplayMode)
GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail
? Expanded( ? Expanded(
child: TextFormField( child: TextFormField(
decoration: const InputDecoration( decoration: const InputDecoration(
@ -340,8 +337,8 @@ class _LogEntryScreenState extends State<LogEntryScreen> {
), ),
) )
: Container(), : Container(),
Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || Settings.glucoseDisplayMode == GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode == Settings.glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail GlucoseDisplayMode.bothForDetail
? IconButton( ? IconButton(
onPressed: () => onPressed: () =>
@ -351,10 +348,10 @@ class _LogEntryScreenState extends State<LogEntryScreen> {
icon: const Icon(Icons.calculate), icon: const Icon(Icons.calculate),
) )
: Container(), : Container(),
Settings.get().glucoseMeasurement == GlucoseMeasurement.mmolPerL || Settings.glucoseMeasurement == GlucoseMeasurement.mmolPerL ||
Settings.get().glucoseDisplayMode == Settings.glucoseDisplayMode ==
GlucoseDisplayMode.both || GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode == Settings.glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail GlucoseDisplayMode.bothForDetail
? Expanded( ? Expanded(
child: TextFormField( child: TextFormField(
@ -382,8 +379,8 @@ class _LogEntryScreenState extends State<LogEntryScreen> {
), ),
) )
: Container(), : Container(),
Settings.get().glucoseDisplayMode == GlucoseDisplayMode.both || Settings.glucoseDisplayMode == GlucoseDisplayMode.both ||
Settings.get().glucoseDisplayMode == Settings.glucoseDisplayMode ==
GlucoseDisplayMode.bothForDetail GlucoseDisplayMode.bothForDetail
? IconButton( ? IconButton(
onPressed: () => onPressed: () =>

View File

@ -324,7 +324,7 @@ class _LogMealDetailScreenState extends State<LogMealDetailScreen> {
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Portion size', labelText: 'Portion size',
suffixText: suffixText:
nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], Settings.nutritionMeasurementSuffix,
alignLabelWithHint: true, alignLabelWithHint: true,
), ),
controller: _portionSizeController, controller: _portionSizeController,
@ -360,7 +360,7 @@ class _LogMealDetailScreenState extends State<LogMealDetailScreen> {
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Carbs per portion', labelText: 'Carbs per portion',
suffixText: suffixText:
nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], Settings.nutritionMeasurementSuffix,
), ),
controller: _carbsPerPortionController, controller: _carbsPerPortionController,
keyboardType: const TextInputType.numberWithOptions( keyboardType: const TextInputType.numberWithOptions(

View File

@ -312,7 +312,7 @@ class _MealDetailScreenState extends State<MealDetailScreen> {
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Portion size', labelText: 'Portion size',
suffixText: suffixText:
nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], Settings.nutritionMeasurementSuffix,
alignLabelWithHint: true, alignLabelWithHint: true,
), ),
controller: _portionSizeController, controller: _portionSizeController,
@ -348,7 +348,7 @@ class _MealDetailScreenState extends State<MealDetailScreen> {
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Carbs per portion', labelText: 'Carbs per portion',
suffixText: suffixText:
nutritionMeasurementSuffixes[Settings.get().nutritionMeasurement.index], Settings.nutritionMeasurementSuffix,
), ),
controller: _carbsPerPortionController, controller: _carbsPerPortionController,
keyboardType: const TextInputType.numberWithOptions( keyboardType: const TextInputType.numberWithOptions(

View File

@ -17,43 +17,58 @@ class SettingsScreen extends StatefulWidget {
class _SettingsScreenState extends State<SettingsScreen> { class _SettingsScreenState extends State<SettingsScreen> {
late Settings _settings; late Settings _settings;
late String _nutritionMeasurementLabel;
late String _glucoseMeasurementLabel;
late bool _onlyDisplayActiveGlucoseMeasurement; late bool _onlyDisplayActiveGlucoseMeasurement;
late bool _displayBothGlucoseMeasurementsInDetailView; late bool _displayBothGlucoseMeasurementsInDetailView;
late bool _displayBothGlucoseMeasurementsInListView; 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 @override
void initState() { void initState() {
super.initState(); super.initState();
reload(); _settings = Settings.get();
} _nutritionMeasurementLabel =
nutritionMeasurementLabels[_settings.nutritionMeasurementIndex];
void onReset() { _glucoseMeasurementLabel =
Settings.reset(); glucoseMeasurementLabels[_settings.glucoseMeasurementIndex];
reload(message: 'Settings have been reset to default'); _onlyDisplayActiveGlucoseMeasurement = _settings.glucoseDisplayModeIndex == GlucoseDisplayMode.activeOnly.index;
} _displayBothGlucoseMeasurementsInDetailView =
_settings.glucoseDisplayModeIndex == GlucoseDisplayMode.both.index ||
void saveSettings() { _settings.glucoseDisplayModeIndex == GlucoseDisplayMode.bothForDetail.index;
Settings.put(Settings( _displayBothGlucoseMeasurementsInListView =
id: _settings.id, _settings.glucoseDisplayModeIndex == GlucoseDisplayMode.both.index ||
nutritionMeasurement: _settings.nutritionMeasurement, _settings.glucoseDisplayModeIndex == GlucoseDisplayMode.bothForList.index;
glucoseDisplayMode: _settings.glucoseDisplayMode, // _dateFormat = _settings.dateFormat;
glucoseMeasurement: _settings.glucoseMeasurement, // _longDateFormat = _settings.longDateFormat;
dateFormat: _settings.dateFormat, // _timeFormat = _settings.timeFormat;
longDateFormat: _settings.longDateFormat, // _longTimeFormat = _settings.longTimeFormat;
timeFormat: _settings.timeFormat, _showConfirmationDialogOnCancel = _settings.showConfirmationDialogOnCancel;
longTimeFormat: _settings.longTimeFormat, _showConfirmationDialogOnDelete = _settings.showConfirmationDialogOnDelete;
showConfirmationDialogOnCancel: _settings.showConfirmationDialogOnCancel, _showConfirmationDialogOnStopEvent =
showConfirmationDialogOnDelete: _settings.showConfirmationDialogOnDelete, _settings.showConfirmationDialogOnStopEvent;
showConfirmationDialogOnStopEvent: // _lowGlucoseMgPerDl = _settings.lowGlucoseMgPerDl;
_settings.showConfirmationDialogOnStopEvent, // _moderateGlucoseMgPerDl = _settings.moderateGlucoseMgPerDl;
lowGlucoseMgPerDl: _settings.lowGlucoseMgPerDl, // _highGlucoseMgPerDl = _settings.highGlucoseMgPerDl;
moderateGlucoseMgPerDl: _settings.moderateGlucoseMgPerDl, // _lowGlucoseMmolPerL = _settings.lowGlucoseMmolPerL;
highGlucoseMgPerDl: _settings.highGlucoseMgPerDl, // _moderateGlucoseMmolPerL = _settings.moderateGlucoseMmolPerL;
lowGlucoseMmolPerL: _settings.lowGlucoseMmolPerL, // _highGlucoseMmolPerDl = _settings.highGlucoseMmolPerDl;
moderateGlucoseMmolPerL: _settings.moderateGlucoseMmolPerL,
highGlucoseMmolPerDl: _settings.highGlucoseMmolPerDl,
));
reload(message: 'Settings updated');
} }
void reload({String? message}) { void reload({String? message}) {
@ -61,17 +76,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
_settings = Settings.get(); _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(() { setState(() {
if (message != null) { if (message != null) {
var snackBar = SnackBar( var snackBar = SnackBar(
@ -85,6 +89,54 @@ class _SettingsScreenState extends State<SettingsScreen> {
}); });
} }
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 { void handleResetAction() async {
Dialogs.showConfirmationDialog( Dialogs.showConfirmationDialog(
context: context, context: context,
@ -101,30 +153,28 @@ class _SettingsScreenState extends State<SettingsScreen> {
), ),
drawer: const Navigation(currentLocation: SettingsScreen.routeName), drawer: const Navigation(currentLocation: SettingsScreen.routeName),
body: SingleChildScrollView( body: SingleChildScrollView(
padding: const EdgeInsets.all(10.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
AutoCompleteDropdownButton<String>( AutoCompleteDropdownButton<String>(
selectedItem: nutritionMeasurementLabels[ selectedItem: _nutritionMeasurementLabel,
_settings.nutritionMeasurement.index],
label: 'Preferred Nutrition Measurement', label: 'Preferred Nutrition Measurement',
items: nutritionMeasurementLabels, items: nutritionMeasurementLabels,
onChanged: (value) { onChanged: (value) {
if (value != null) { if (value != null) {
_settings.nutritionMeasurement = NutritionMeasurement.values _nutritionMeasurementLabel = value;
.elementAt(nutritionMeasurementLabels.indexOf(value));
saveSettings(); saveSettings();
} }
}, },
), ),
AutoCompleteDropdownButton<String>( AutoCompleteDropdownButton<String>(
selectedItem: selectedItem: _glucoseMeasurementLabel,
glucoseMeasurementLabels[_settings.glucoseMeasurement.index],
label: 'Preferred Glucose Measurement', label: 'Preferred Glucose Measurement',
items: glucoseMeasurementLabels, items: glucoseMeasurementLabels,
onChanged: (value) { onChanged: (value) {
if (value != null) { if (value != null) {
_settings.glucoseMeasurement = GlucoseMeasurement.values _glucoseMeasurementLabel = value;
.elementAt(glucoseMeasurementLabels.indexOf(value));
saveSettings(); saveSettings();
} }
}, },
@ -132,46 +182,54 @@ class _SettingsScreenState extends State<SettingsScreen> {
BooleanFormField( BooleanFormField(
value: _onlyDisplayActiveGlucoseMeasurement, value: _onlyDisplayActiveGlucoseMeasurement,
label: 'only display active glucose measurement', label: 'only display active glucose measurement',
onChanged: (_) { onChanged: (value) {
GlucoseDisplayMode mode = _settings.glucoseDisplayMode == _onlyDisplayActiveGlucoseMeasurement = value;
GlucoseDisplayMode.activeOnly
? GlucoseDisplayMode.both
: GlucoseDisplayMode.activeOnly;
_settings.glucoseDisplayMode = mode;
saveSettings(); saveSettings();
}, },
), ),
BooleanFormField( BooleanFormField(
value: _displayBothGlucoseMeasurementsInDetailView, value: _displayBothGlucoseMeasurementsInDetailView,
enabled: enabled: !_onlyDisplayActiveGlucoseMeasurement,
!_onlyDisplayActiveGlucoseMeasurement,
label: 'display both glucose measurements in detail view', label: 'display both glucose measurements in detail view',
onChanged: (_) { onChanged: (value) {
GlucoseDisplayMode mode = _displayBothGlucoseMeasurementsInDetailView = value;
_settings.glucoseDisplayMode == GlucoseDisplayMode.both
? GlucoseDisplayMode.bothForList
: _settings.glucoseDisplayMode ==
GlucoseDisplayMode.bothForList
? GlucoseDisplayMode.both
: GlucoseDisplayMode.activeOnly;
_settings.glucoseDisplayMode = mode;
saveSettings(); saveSettings();
}, },
), ),
BooleanFormField( BooleanFormField(
value: _displayBothGlucoseMeasurementsInListView, value: _displayBothGlucoseMeasurementsInListView,
enabled: enabled: !_onlyDisplayActiveGlucoseMeasurement,
!_onlyDisplayActiveGlucoseMeasurement,
label: 'display both glucose measurements in list view', label: 'display both glucose measurements in list view',
onChanged: (_) { onChanged: (value) {
GlucoseDisplayMode mode = _displayBothGlucoseMeasurementsInListView = value;
_settings.glucoseDisplayMode == GlucoseDisplayMode.both saveSettings();
? GlucoseDisplayMode.bothForDetail },
: _settings.glucoseDisplayMode == ),
GlucoseDisplayMode.bothForDetail const Padding(
? GlucoseDisplayMode.both padding: EdgeInsets.only(top: 10.0),
: GlucoseDisplayMode.activeOnly; child: Text('Confirmation prompts'),
_settings.glucoseDisplayMode = mode; ),
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(); saveSettings();
}, },
), ),