From f0f88986271976422b2334fbe9651eef71bb6feb Mon Sep 17 00:00:00 2001 From: spinel Date: Thu, 25 Nov 2021 19:25:13 +0100 Subject: [PATCH] fix log entry tabs --- TODO | 33 +- lib/models/accuracy.dart | 4 +- lib/models/basal.dart | 2 + lib/models/basal_profile.dart | 2 + lib/models/bolus.dart | 18 +- lib/models/bolus_profile.dart | 2 + lib/models/log_bolus.dart | 7 +- lib/models/log_entry.dart | 2 + lib/models/log_event.dart | 2 + lib/objectbox-model.json | 168 +++-- lib/objectbox.g.dart | 609 ++++++++++++------ lib/screens/log/log.dart | 8 +- .../log/log_entry/log_bolus_detail.dart | 86 ++- .../log/log_entry/log_event_detail.dart | 1 + .../log/log_entry/log_meal_detail.dart | 4 +- 15 files changed, 638 insertions(+), 310 deletions(-) diff --git a/TODO b/TODO index c6a26d8..0977761 100644 --- a/TODO +++ b/TODO @@ -1,13 +1,15 @@ MAIN TASKS: General/Framework: - ☐ add active/deleted flag to all data models + ☐ add deleted flag to all data models + ☐ adjust remove and fetch methods accordingly ☐ find a general way to deal with duration fields + ☐ implement tostring methods for all models Accuracies: ☐ implement reordering Basal/Bolus: - ☐ create distinct visual mode for picking the active profile + ☐ create distinct visual mode for picking the active profile (or remove active flag) Log Overview: ☐ add active events view (as main menu item?) @@ -18,18 +20,24 @@ MAIN TASKS: Log Entry: ☐ replace meal and glucose boli with logbolus entities - ☐ fix logmeals/logboli/logevents (probably use queries for associated items instead of onetomany) + ☐ check for multiple active events with temporary basal/bolus profiles Event Types: - ☐ add option to change bolus/basal profile for event duration + ☐ add option to change bolus/basal profile for event duration (dropdown with detail option) + ☐ add reminder option + ☐ implement reminders as push notification Settings: ☐ add objectbox class and use instead of shared preferences ☐ add fields for date and time formats ☐ add fields for glucose target + ☐ add option to hide warning dialogs on cancel + ☐ add option to hide extra customization options (ie. changing pre calculated values) + ☐ add setting for decimal places FUTURE TASKS: General/Framework: + ☐ 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) @@ -38,11 +46,12 @@ FUTURE TASKS: ☐ add pagination -ARCHIVE: - ✔ add tab for bolus overview @done(21-11-24 22:05) @project(Log Entry) - ✔ calculate bolus suggestions according to active profile @done(21-11-24 22:05) @project(Log Entry) - ✔ place dropdown items right below their input @done(21-11-23 20:33) @project(General/Framework) - ✔ add autocomplete function to dropdowns @done(21-11-23 20:33) @project(General/Framework) - ✔ use local database instead of back4app @done(21-11-07 18:53) @project(General/Framework) - ✔ use ids instead of passing entities around where possible @done(21-11-10 00:06) @project(General/Framework) - ✔ add time picker for entry date/time @done(21-11-10 00:06) @project(Log Entry) +Archive: + ✔ fix logmeals/logboli/logevents @done(21-11-25 17:10) @project(MAIN TASKS.Log Entry) + ✔ add tab for bolus overview @done(21-11-24 22:05) @project(MAIN TASKS.Log Entry) + ✔ calculate bolus suggestions according to active profile @done(21-11-24 22:05) @project(MAIN TASKS.Log Entry) + ✔ place dropdown items right below their input @done(21-11-23 20:33) @project(MAIN TASKS.General/Framework) + ✔ add autocomplete function to dropdowns @done(21-11-23 20:33) @project(MAIN TASKS.General/Framework) + ✔ use local database instead of back4app @done(21-11-07 18:53) @project(MAIN TASKS.General/Framework) + ✔ use ids instead of passing entities around where possible @done(21-11-10 00:06) @project(MAIN TASKS.General/Framework) + ✔ add time picker for entry date/time @done(21-11-10 00:06) @project(MAIN TASKS.Log Entry) diff --git a/lib/models/accuracy.dart b/lib/models/accuracy.dart index 571dc34..eb245ba 100644 --- a/lib/models/accuracy.dart +++ b/lib/models/accuracy.dart @@ -1,7 +1,9 @@ import 'package:diameter/main.dart'; import 'package:diameter/objectbox.g.dart'; +// ignore: unnecessary_import +import 'package:objectbox/objectbox.dart'; -@Entity(uid: 3095978685310268382) +@Entity(uid: 291512798403320400) class Accuracy { static final Box box = objectBox.store.box(); diff --git a/lib/models/basal.dart b/lib/models/basal.dart index 35d1788..f8fd581 100644 --- a/lib/models/basal.dart +++ b/lib/models/basal.dart @@ -1,6 +1,8 @@ import 'package:diameter/main.dart'; import 'package:diameter/models/basal_profile.dart'; import 'package:diameter/objectbox.g.dart'; +// ignore: unnecessary_import +import 'package:objectbox/objectbox.dart'; @Entity(uid: 1467758525778521891) class Basal { diff --git a/lib/models/basal_profile.dart b/lib/models/basal_profile.dart index f02de8f..988f6d8 100644 --- a/lib/models/basal_profile.dart +++ b/lib/models/basal_profile.dart @@ -1,5 +1,7 @@ import 'package:diameter/main.dart'; import 'package:diameter/objectbox.g.dart'; +// ignore: unnecessary_import +import 'package:objectbox/objectbox.dart'; @Entity(uid: 3613736032926903785) class BasalProfile { diff --git a/lib/models/bolus.dart b/lib/models/bolus.dart index afee10d..ffc6f03 100644 --- a/lib/models/bolus.dart +++ b/lib/models/bolus.dart @@ -1,8 +1,11 @@ +import 'package:diameter/config.dart'; import 'package:diameter/main.dart'; import 'package:diameter/models/bolus_profile.dart'; import 'package:diameter/objectbox.g.dart'; import 'package:diameter/utils/date_time_utils.dart'; import 'package:flutter/material.dart'; +// ignore: unnecessary_import +import 'package:objectbox/objectbox.dart'; @Entity(uid: 3417770529060202389) class Bolus { @@ -45,13 +48,18 @@ class Bolus { // ignore: todo // TODO: check if an event is active that would change the active profile final bolusProfile = BolusProfile.getActive(); - final time = DateTimeUtils.convertTimeOfDayToDateTime(TimeOfDay.fromDateTime(dateTime)); + final time = DateTimeUtils.convertTimeOfDayToDateTime( + TimeOfDay.fromDateTime(dateTime)); if (bolusProfile != null) { final rates = Bolus.getAllForProfile(bolusProfile.id); - final result = rates.where((rate) => - (time.isAfter(rate.startTime) || - time.isAtSameMomentAs(rate.startTime)) && - time.isBefore(rate.endTime)); + final result = rates.where((rate) { + DateTime endTime = rate.endTime == dummyDate + ? rate.endTime.add(const Duration(days: 1)) + : rate.endTime; + return (time.isAfter(rate.startTime) || + time.isAtSameMomentAs(rate.startTime)) && + time.isBefore(endTime); + }); return result.length != 1 ? null : result.single; } return null; diff --git a/lib/models/bolus_profile.dart b/lib/models/bolus_profile.dart index a4e9936..74fcc29 100644 --- a/lib/models/bolus_profile.dart +++ b/lib/models/bolus_profile.dart @@ -1,5 +1,7 @@ import 'package:diameter/main.dart'; import 'package:diameter/objectbox.g.dart'; +// ignore: unnecessary_import +import 'package:objectbox/objectbox.dart'; @Entity(uid: 8812452529027052317) class BolusProfile { diff --git a/lib/models/log_bolus.dart b/lib/models/log_bolus.dart index 70b1d59..cd1b646 100644 --- a/lib/models/log_bolus.dart +++ b/lib/models/log_bolus.dart @@ -3,8 +3,9 @@ import 'package:diameter/models/bolus.dart'; import 'package:diameter/models/log_entry.dart'; import 'package:diameter/models/log_meal.dart'; import 'package:diameter/objectbox.g.dart'; +import 'package:objectbox/objectbox.dart'; -@Entity(uid: 0) +@Entity(uid: 8033487006694871160) class LogBolus { static final Box box = objectBox.store.box(); @@ -14,7 +15,7 @@ class LogBolus { int? delay; int? mgPerDl; double? mmolPerL; - bool manuallyAdjusted; + bool setManually; String? notes; final logEntry = ToOne(); @@ -28,7 +29,7 @@ class LogBolus { this.delay, this.mgPerDl, this.mmolPerL, - this.manuallyAdjusted = false, + this.setManually = false, this.notes, }); diff --git a/lib/models/log_entry.dart b/lib/models/log_entry.dart index e6a3577..c9c955b 100644 --- a/lib/models/log_entry.dart +++ b/lib/models/log_entry.dart @@ -3,6 +3,8 @@ import 'package:diameter/models/log_bolus.dart'; import 'package:diameter/models/log_event.dart'; import 'package:diameter/models/log_meal.dart'; import 'package:diameter/objectbox.g.dart'; +// ignore: unnecessary_import +import 'package:objectbox/objectbox.dart'; @Entity(uid: 752131069307970560) class LogEntry { diff --git a/lib/models/log_event.dart b/lib/models/log_event.dart index 6122701..bf47054 100644 --- a/lib/models/log_event.dart +++ b/lib/models/log_event.dart @@ -2,6 +2,8 @@ import 'package:diameter/main.dart'; import 'package:diameter/models/log_entry.dart'; import 'package:diameter/models/log_event_type.dart'; import 'package:diameter/objectbox.g.dart'; +// ignore: unnecessary_import +import 'package:objectbox/objectbox.dart'; @Entity(uid: 4303325892753185970) class LogEvent { diff --git a/lib/objectbox-model.json b/lib/objectbox-model.json index 65b048e..86a34ec 100644 --- a/lib/objectbox-model.json +++ b/lib/objectbox-model.json @@ -3,45 +3,6 @@ "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", "entities": [ - { - "id": "1:3095978685310268382", - "lastPropertyId": "6:5471636804765937328", - "name": "Accuracy", - "properties": [ - { - "id": "1:3455702077061719523", - "name": "id", - "type": 6, - "flags": 1 - }, - { - "id": "2:1048198814030724077", - "name": "value", - "type": 9 - }, - { - "id": "3:9003780003858349085", - "name": "forCarbsRatio", - "type": 1 - }, - { - "id": "4:5421422436108145565", - "name": "forPortionSize", - "type": 1 - }, - { - "id": "5:7741631874181070179", - "name": "confidenceRating", - "type": 6 - }, - { - "id": "6:5471636804765937328", - "name": "notes", - "type": 9 - } - ], - "relations": [] - }, { "id": "2:1467758525778521891", "lastPropertyId": "5:3908367275335317130", @@ -632,17 +593,138 @@ } ], "relations": [] + }, + { + "id": "14:8033487006694871160", + "lastPropertyId": "11:4818762109001810295", + "name": "LogBolus", + "properties": [ + { + "id": "1:8254237730262024662", + "name": "id", + "type": 6, + "flags": 1 + }, + { + "id": "2:7669701519569266656", + "name": "units", + "type": 8 + }, + { + "id": "3:1967840431906109999", + "name": "carbs", + "type": 8 + }, + { + "id": "4:5520321978435312625", + "name": "delay", + "type": 6 + }, + { + "id": "5:6855574218883169324", + "name": "mgPerDl", + "type": 6 + }, + { + "id": "6:5313708456544000157", + "name": "mmolPerL", + "type": 8 + }, + { + "id": "7:3065420032567707091", + "name": "setManually", + "type": 1 + }, + { + "id": "8:2967613978873295525", + "name": "notes", + "type": 9 + }, + { + "id": "9:5454965717985089938", + "name": "logEntryId", + "type": 11, + "flags": 520, + "indexId": "22:5852072074740543047", + "relationTarget": "LogEntry" + }, + { + "id": "10:4105009806564072037", + "name": "rateId", + "type": 11, + "flags": 520, + "indexId": "23:1594553054621930876", + "relationTarget": "Bolus" + }, + { + "id": "11:4818762109001810295", + "name": "mealId", + "type": 11, + "flags": 520, + "indexId": "24:4224983816051843140", + "relationTarget": "LogMeal" + } + ], + "relations": [] + }, + { + "id": "15:291512798403320400", + "lastPropertyId": "6:6625101003527710274", + "name": "Accuracy", + "properties": [ + { + "id": "1:8405388350474524599", + "name": "id", + "type": 6, + "flags": 1 + }, + { + "id": "2:1919049381880760479", + "name": "value", + "type": 9 + }, + { + "id": "3:7181081526218678274", + "name": "forCarbsRatio", + "type": 1 + }, + { + "id": "4:3576006369067328383", + "name": "forPortionSize", + "type": 1 + }, + { + "id": "5:7027546512578846894", + "name": "confidenceRating", + "type": 6 + }, + { + "id": "6:6625101003527710274", + "name": "notes", + "type": 9 + } + ], + "relations": [] } ], - "lastEntityId": "13:1283034494527412242", - "lastIndexId": "21:1931330716440762729", + "lastEntityId": "15:291512798403320400", + "lastIndexId": "24:4224983816051843140", "lastRelationId": "0:0", "lastSequenceId": "0:0", "modelVersion": 5, "modelVersionParserMinimum": 5, - "retiredEntityUids": [], + "retiredEntityUids": [ + 3095978685310268382 + ], "retiredIndexUids": [], - "retiredPropertyUids": [], + "retiredPropertyUids": [ + 3455702077061719523, + 1048198814030724077, + 9003780003858349085, + 5421422436108145565, + 7741631874181070179, + 5471636804765937328 + ], "retiredRelationUids": [], "version": 1 } \ No newline at end of file diff --git a/lib/objectbox.g.dart b/lib/objectbox.g.dart index c5656d6..814b19d 100644 --- a/lib/objectbox.g.dart +++ b/lib/objectbox.g.dart @@ -14,6 +14,7 @@ import 'models/basal.dart'; import 'models/basal_profile.dart'; import 'models/bolus.dart'; import 'models/bolus_profile.dart'; +import 'models/log_bolus.dart'; import 'models/log_entry.dart'; import 'models/log_event.dart'; import 'models/log_event_type.dart'; @@ -26,45 +27,6 @@ import 'models/meal_source.dart'; export 'package:objectbox/objectbox.dart'; // so that callers only have to import this file final _entities = [ - ModelEntity( - id: const IdUid(1, 3095978685310268382), - name: 'Accuracy', - lastPropertyId: const IdUid(6, 5471636804765937328), - flags: 0, - properties: [ - ModelProperty( - id: const IdUid(1, 3455702077061719523), - name: 'id', - type: 6, - flags: 1), - ModelProperty( - id: const IdUid(2, 1048198814030724077), - name: 'value', - type: 9, - flags: 0), - ModelProperty( - id: const IdUid(3, 9003780003858349085), - name: 'forCarbsRatio', - type: 1, - flags: 0), - ModelProperty( - id: const IdUid(4, 5421422436108145565), - name: 'forPortionSize', - type: 1, - flags: 0), - ModelProperty( - id: const IdUid(5, 7741631874181070179), - name: 'confidenceRating', - type: 6, - flags: 0), - ModelProperty( - id: const IdUid(6, 5471636804765937328), - name: 'notes', - type: 9, - flags: 0) - ], - relations: [], - backlinks: []), ModelEntity( id: const IdUid(2, 1467758525778521891), name: 'Basal', @@ -265,7 +227,9 @@ final _entities = [ name: 'endedEvents', srcEntity: 'LogEvent', srcField: 'endLogEntry'), - ModelBacklink(name: 'meals', srcEntity: 'LogMeal', srcField: 'logEntry') + ModelBacklink( + name: 'meals', srcEntity: 'LogMeal', srcField: 'logEntry'), + ModelBacklink(name: 'boli', srcEntity: 'LogBolus', srcField: 'logEntry') ]), ModelEntity( id: const IdUid(7, 4303325892753185970), @@ -642,6 +606,115 @@ final _entities = [ relationTarget: 'Accuracy') ], relations: [], + backlinks: []), + ModelEntity( + id: const IdUid(14, 8033487006694871160), + name: 'LogBolus', + lastPropertyId: const IdUid(11, 4818762109001810295), + flags: 0, + properties: [ + ModelProperty( + id: const IdUid(1, 8254237730262024662), + name: 'id', + type: 6, + flags: 1), + ModelProperty( + id: const IdUid(2, 7669701519569266656), + name: 'units', + type: 8, + flags: 0), + ModelProperty( + id: const IdUid(3, 1967840431906109999), + name: 'carbs', + type: 8, + flags: 0), + ModelProperty( + id: const IdUid(4, 5520321978435312625), + name: 'delay', + type: 6, + flags: 0), + ModelProperty( + id: const IdUid(5, 6855574218883169324), + name: 'mgPerDl', + type: 6, + flags: 0), + ModelProperty( + id: const IdUid(6, 5313708456544000157), + name: 'mmolPerL', + type: 8, + flags: 0), + ModelProperty( + id: const IdUid(7, 3065420032567707091), + name: 'setManually', + type: 1, + flags: 0), + ModelProperty( + id: const IdUid(8, 2967613978873295525), + name: 'notes', + type: 9, + flags: 0), + ModelProperty( + id: const IdUid(9, 5454965717985089938), + name: 'logEntryId', + type: 11, + flags: 520, + indexId: const IdUid(22, 5852072074740543047), + relationTarget: 'LogEntry'), + ModelProperty( + id: const IdUid(10, 4105009806564072037), + name: 'rateId', + type: 11, + flags: 520, + indexId: const IdUid(23, 1594553054621930876), + relationTarget: 'Bolus'), + ModelProperty( + id: const IdUid(11, 4818762109001810295), + name: 'mealId', + type: 11, + flags: 520, + indexId: const IdUid(24, 4224983816051843140), + relationTarget: 'LogMeal') + ], + relations: [], + backlinks: []), + ModelEntity( + id: const IdUid(15, 291512798403320400), + name: 'Accuracy', + lastPropertyId: const IdUid(6, 6625101003527710274), + flags: 0, + properties: [ + ModelProperty( + id: const IdUid(1, 8405388350474524599), + name: 'id', + type: 6, + flags: 1), + ModelProperty( + id: const IdUid(2, 1919049381880760479), + name: 'value', + type: 9, + flags: 0), + ModelProperty( + id: const IdUid(3, 7181081526218678274), + name: 'forCarbsRatio', + type: 1, + flags: 0), + ModelProperty( + id: const IdUid(4, 3576006369067328383), + name: 'forPortionSize', + type: 1, + flags: 0), + ModelProperty( + id: const IdUid(5, 7027546512578846894), + name: 'confidenceRating', + type: 6, + flags: 0), + ModelProperty( + id: const IdUid(6, 6625101003527710274), + name: 'notes', + type: 9, + flags: 0) + ], + relations: [], backlinks: []) ]; @@ -665,62 +738,28 @@ Future openStore( ModelDefinition getObjectBoxModel() { final model = ModelInfo( entities: _entities, - lastEntityId: const IdUid(13, 1283034494527412242), - lastIndexId: const IdUid(21, 1931330716440762729), + lastEntityId: const IdUid(15, 291512798403320400), + lastIndexId: const IdUid(24, 4224983816051843140), lastRelationId: const IdUid(0, 0), lastSequenceId: const IdUid(0, 0), - retiredEntityUids: const [], + retiredEntityUids: const [3095978685310268382], retiredIndexUids: const [], - retiredPropertyUids: const [], + retiredPropertyUids: const [ + 3455702077061719523, + 1048198814030724077, + 9003780003858349085, + 5421422436108145565, + 7741631874181070179, + 5471636804765937328 + ], retiredRelationUids: const [], modelVersion: 5, modelVersionParserMinimum: 5, version: 1); final bindings = { - Accuracy: EntityDefinition( - model: _entities[0], - toOneRelations: (Accuracy object) => [], - toManyRelations: (Accuracy object) => {}, - getId: (Accuracy object) => object.id, - setId: (Accuracy object, int id) { - object.id = id; - }, - objectToFB: (Accuracy object, fb.Builder fbb) { - final valueOffset = fbb.writeString(object.value); - final notesOffset = - object.notes == null ? null : fbb.writeString(object.notes!); - fbb.startTable(7); - fbb.addInt64(0, object.id); - fbb.addOffset(1, valueOffset); - fbb.addBool(2, object.forCarbsRatio); - fbb.addBool(3, object.forPortionSize); - fbb.addInt64(4, object.confidenceRating); - fbb.addOffset(5, notesOffset); - fbb.finish(fbb.endTable()); - return object.id; - }, - objectFromFB: (Store store, ByteData fbData) { - final buffer = fb.BufferContext(fbData); - final rootOffset = buffer.derefObject(0); - - final object = Accuracy( - id: const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0), - value: - const fb.StringReader().vTableGet(buffer, rootOffset, 6, ''), - forCarbsRatio: - const fb.BoolReader().vTableGet(buffer, rootOffset, 8, false), - forPortionSize: const fb.BoolReader() - .vTableGet(buffer, rootOffset, 10, false), - confidenceRating: const fb.Int64Reader() - .vTableGetNullable(buffer, rootOffset, 12), - notes: const fb.StringReader() - .vTableGetNullable(buffer, rootOffset, 14)); - - return object; - }), Basal: EntityDefinition( - model: _entities[1], + model: _entities[0], toOneRelations: (Basal object) => [object.basalProfile], toManyRelations: (Basal object) => {}, getId: (Basal object) => object.id, @@ -755,7 +794,7 @@ ModelDefinition getObjectBoxModel() { return object; }), BasalProfile: EntityDefinition( - model: _entities[2], + model: _entities[1], toOneRelations: (BasalProfile object) => [], toManyRelations: (BasalProfile object) => {}, getId: (BasalProfile object) => object.id, @@ -790,7 +829,7 @@ ModelDefinition getObjectBoxModel() { return object; }), Bolus: EntityDefinition( - model: _entities[3], + model: _entities[2], toOneRelations: (Bolus object) => [object.bolusProfile], toManyRelations: (Bolus object) => {}, getId: (Bolus object) => object.id, @@ -834,7 +873,7 @@ ModelDefinition getObjectBoxModel() { return object; }), BolusProfile: EntityDefinition( - model: _entities[4], + model: _entities[3], toOneRelations: (BolusProfile object) => [], toManyRelations: (BolusProfile object) => {}, getId: (BolusProfile object) => object.id, @@ -869,7 +908,7 @@ ModelDefinition getObjectBoxModel() { return object; }), LogEntry: EntityDefinition( - model: _entities[5], + model: _entities[4], toOneRelations: (LogEntry object) => [], toManyRelations: (LogEntry object) => { RelInfo.toOneBacklink( @@ -880,7 +919,10 @@ ModelDefinition getObjectBoxModel() { object.endedEvents, RelInfo.toOneBacklink( 10, object.id, (LogMeal srcObject) => srcObject.logEntry): - object.meals + object.meals, + RelInfo.toOneBacklink( + 9, object.id, (LogBolus srcObject) => srcObject.logEntry): + object.boli }, getId: (LogEntry object) => object.id, setId: (LogEntry object, int id) { @@ -939,10 +981,16 @@ ModelDefinition getObjectBoxModel() { RelInfo.toOneBacklink( 10, object.id, (LogMeal srcObject) => srcObject.logEntry), store.box()); + InternalToManyAccess.setRelInfo( + object.boli, + store, + RelInfo.toOneBacklink( + 9, object.id, (LogBolus srcObject) => srcObject.logEntry), + store.box()); return object; }), LogEvent: EntityDefinition( - model: _entities[6], + model: _entities[5], toOneRelations: (LogEvent object) => [object.logEntry, object.endLogEntry, object.eventType], toManyRelations: (LogEvent object) => {}, @@ -993,7 +1041,7 @@ ModelDefinition getObjectBoxModel() { return object; }), LogEventType: EntityDefinition( - model: _entities[7], + model: _entities[6], toOneRelations: (LogEventType object) => [], toManyRelations: (LogEventType object) => {}, getId: (LogEventType object) => object.id, @@ -1031,7 +1079,7 @@ ModelDefinition getObjectBoxModel() { return object; }), LogMeal: EntityDefinition( - model: _entities[8], + model: _entities[7], toOneRelations: (LogMeal object) => [ object.logEntry, object.meal, @@ -1116,7 +1164,7 @@ ModelDefinition getObjectBoxModel() { return object; }), Meal: EntityDefinition( - model: _entities[9], + model: _entities[8], toOneRelations: (Meal object) => [ object.mealSource, object.mealCategory, @@ -1188,7 +1236,7 @@ ModelDefinition getObjectBoxModel() { return object; }), MealCategory: EntityDefinition( - model: _entities[10], + model: _entities[9], toOneRelations: (MealCategory object) => [], toManyRelations: (MealCategory object) => {}, getId: (MealCategory object) => object.id, @@ -1220,7 +1268,7 @@ ModelDefinition getObjectBoxModel() { return object; }), MealPortionType: EntityDefinition( - model: _entities[11], + model: _entities[10], toOneRelations: (MealPortionType object) => [], toManyRelations: (MealPortionType object) => {}, getId: (MealPortionType object) => object.id, @@ -1252,7 +1300,7 @@ ModelDefinition getObjectBoxModel() { return object; }), MealSource: EntityDefinition( - model: _entities[12], + model: _entities[11], toOneRelations: (MealSource object) => [ object.defaultMealCategory, object.defaultMealPortionType, @@ -1302,393 +1350,538 @@ ModelDefinition getObjectBoxModel() { const fb.Int64Reader().vTableGet(buffer, rootOffset, 16, 0); object.defaultPortionSizeAccuracy.attach(store); return object; + }), + LogBolus: EntityDefinition( + model: _entities[12], + toOneRelations: (LogBolus object) => + [object.logEntry, object.rate, object.meal], + toManyRelations: (LogBolus object) => {}, + getId: (LogBolus object) => object.id, + setId: (LogBolus object, int id) { + object.id = id; + }, + objectToFB: (LogBolus object, fb.Builder fbb) { + final notesOffset = + object.notes == null ? null : fbb.writeString(object.notes!); + fbb.startTable(12); + fbb.addInt64(0, object.id); + fbb.addFloat64(1, object.units); + fbb.addFloat64(2, object.carbs); + fbb.addInt64(3, object.delay); + fbb.addInt64(4, object.mgPerDl); + fbb.addFloat64(5, object.mmolPerL); + fbb.addBool(6, object.setManually); + fbb.addOffset(7, notesOffset); + fbb.addInt64(8, object.logEntry.targetId); + fbb.addInt64(9, object.rate.targetId); + fbb.addInt64(10, object.meal.targetId); + fbb.finish(fbb.endTable()); + return object.id; + }, + objectFromFB: (Store store, ByteData fbData) { + final buffer = fb.BufferContext(fbData); + final rootOffset = buffer.derefObject(0); + + final object = LogBolus( + id: const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0), + units: + const fb.Float64Reader().vTableGet(buffer, rootOffset, 6, 0), + carbs: const fb.Float64Reader() + .vTableGetNullable(buffer, rootOffset, 8), + delay: const fb.Int64Reader() + .vTableGetNullable(buffer, rootOffset, 10), + mgPerDl: const fb.Int64Reader() + .vTableGetNullable(buffer, rootOffset, 12), + mmolPerL: const fb.Float64Reader() + .vTableGetNullable(buffer, rootOffset, 14), + setManually: const fb.BoolReader() + .vTableGet(buffer, rootOffset, 16, false), + notes: const fb.StringReader() + .vTableGetNullable(buffer, rootOffset, 18)); + object.logEntry.targetId = + const fb.Int64Reader().vTableGet(buffer, rootOffset, 20, 0); + object.logEntry.attach(store); + object.rate.targetId = + const fb.Int64Reader().vTableGet(buffer, rootOffset, 22, 0); + object.rate.attach(store); + object.meal.targetId = + const fb.Int64Reader().vTableGet(buffer, rootOffset, 24, 0); + object.meal.attach(store); + return object; + }), + Accuracy: EntityDefinition( + model: _entities[13], + toOneRelations: (Accuracy object) => [], + toManyRelations: (Accuracy object) => {}, + getId: (Accuracy object) => object.id, + setId: (Accuracy object, int id) { + object.id = id; + }, + objectToFB: (Accuracy object, fb.Builder fbb) { + final valueOffset = fbb.writeString(object.value); + final notesOffset = + object.notes == null ? null : fbb.writeString(object.notes!); + fbb.startTable(7); + fbb.addInt64(0, object.id); + fbb.addOffset(1, valueOffset); + fbb.addBool(2, object.forCarbsRatio); + fbb.addBool(3, object.forPortionSize); + fbb.addInt64(4, object.confidenceRating); + fbb.addOffset(5, notesOffset); + fbb.finish(fbb.endTable()); + return object.id; + }, + objectFromFB: (Store store, ByteData fbData) { + final buffer = fb.BufferContext(fbData); + final rootOffset = buffer.derefObject(0); + + final object = Accuracy( + id: const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0), + value: + const fb.StringReader().vTableGet(buffer, rootOffset, 6, ''), + forCarbsRatio: + const fb.BoolReader().vTableGet(buffer, rootOffset, 8, false), + forPortionSize: const fb.BoolReader() + .vTableGet(buffer, rootOffset, 10, false), + confidenceRating: const fb.Int64Reader() + .vTableGetNullable(buffer, rootOffset, 12), + notes: const fb.StringReader() + .vTableGetNullable(buffer, rootOffset, 14)); + + return object; }) }; return ModelDefinition(model, bindings); } -/// [Accuracy] entity fields to define ObjectBox queries. -class Accuracy_ { - /// see [Accuracy.id] - static final id = QueryIntegerProperty(_entities[0].properties[0]); - - /// see [Accuracy.value] - static final value = - QueryStringProperty(_entities[0].properties[1]); - - /// see [Accuracy.forCarbsRatio] - static final forCarbsRatio = - QueryBooleanProperty(_entities[0].properties[2]); - - /// see [Accuracy.forPortionSize] - static final forPortionSize = - QueryBooleanProperty(_entities[0].properties[3]); - - /// see [Accuracy.confidenceRating] - static final confidenceRating = - QueryIntegerProperty(_entities[0].properties[4]); - - /// see [Accuracy.notes] - static final notes = - QueryStringProperty(_entities[0].properties[5]); -} - /// [Basal] entity fields to define ObjectBox queries. class Basal_ { /// see [Basal.id] - static final id = QueryIntegerProperty(_entities[1].properties[0]); + static final id = QueryIntegerProperty(_entities[0].properties[0]); /// see [Basal.startTime] static final startTime = - QueryIntegerProperty(_entities[1].properties[1]); + QueryIntegerProperty(_entities[0].properties[1]); /// see [Basal.endTime] static final endTime = - QueryIntegerProperty(_entities[1].properties[2]); + QueryIntegerProperty(_entities[0].properties[2]); /// see [Basal.units] - static final units = QueryDoubleProperty(_entities[1].properties[3]); + static final units = QueryDoubleProperty(_entities[0].properties[3]); /// see [Basal.basalProfile] static final basalProfile = - QueryRelationToOne(_entities[1].properties[4]); + QueryRelationToOne(_entities[0].properties[4]); } /// [BasalProfile] entity fields to define ObjectBox queries. class BasalProfile_ { /// see [BasalProfile.id] static final id = - QueryIntegerProperty(_entities[2].properties[0]); + QueryIntegerProperty(_entities[1].properties[0]); /// see [BasalProfile.name] static final name = - QueryStringProperty(_entities[2].properties[1]); + QueryStringProperty(_entities[1].properties[1]); /// see [BasalProfile.active] static final active = - QueryBooleanProperty(_entities[2].properties[2]); + QueryBooleanProperty(_entities[1].properties[2]); /// see [BasalProfile.notes] static final notes = - QueryStringProperty(_entities[2].properties[3]); + QueryStringProperty(_entities[1].properties[3]); } /// [Bolus] entity fields to define ObjectBox queries. class Bolus_ { /// see [Bolus.id] - static final id = QueryIntegerProperty(_entities[3].properties[0]); + static final id = QueryIntegerProperty(_entities[2].properties[0]); /// see [Bolus.startTime] static final startTime = - QueryIntegerProperty(_entities[3].properties[1]); + QueryIntegerProperty(_entities[2].properties[1]); /// see [Bolus.endTime] static final endTime = - QueryIntegerProperty(_entities[3].properties[2]); + QueryIntegerProperty(_entities[2].properties[2]); /// see [Bolus.units] - static final units = QueryDoubleProperty(_entities[3].properties[3]); + static final units = QueryDoubleProperty(_entities[2].properties[3]); /// see [Bolus.carbs] - static final carbs = QueryDoubleProperty(_entities[3].properties[4]); + static final carbs = QueryDoubleProperty(_entities[2].properties[4]); /// see [Bolus.mgPerDl] static final mgPerDl = - QueryIntegerProperty(_entities[3].properties[5]); + QueryIntegerProperty(_entities[2].properties[5]); /// see [Bolus.mmolPerL] static final mmolPerL = - QueryDoubleProperty(_entities[3].properties[6]); + QueryDoubleProperty(_entities[2].properties[6]); /// see [Bolus.bolusProfile] static final bolusProfile = - QueryRelationToOne(_entities[3].properties[7]); + QueryRelationToOne(_entities[2].properties[7]); } /// [BolusProfile] entity fields to define ObjectBox queries. class BolusProfile_ { /// see [BolusProfile.id] static final id = - QueryIntegerProperty(_entities[4].properties[0]); + QueryIntegerProperty(_entities[3].properties[0]); /// see [BolusProfile.name] static final name = - QueryStringProperty(_entities[4].properties[1]); + QueryStringProperty(_entities[3].properties[1]); /// see [BolusProfile.active] static final active = - QueryBooleanProperty(_entities[4].properties[2]); + QueryBooleanProperty(_entities[3].properties[2]); /// see [BolusProfile.notes] static final notes = - QueryStringProperty(_entities[4].properties[3]); + QueryStringProperty(_entities[3].properties[3]); } /// [LogEntry] entity fields to define ObjectBox queries. class LogEntry_ { /// see [LogEntry.id] - static final id = QueryIntegerProperty(_entities[5].properties[0]); + static final id = QueryIntegerProperty(_entities[4].properties[0]); /// see [LogEntry.time] static final time = - QueryIntegerProperty(_entities[5].properties[1]); + QueryIntegerProperty(_entities[4].properties[1]); /// see [LogEntry.mgPerDl] static final mgPerDl = - QueryIntegerProperty(_entities[5].properties[2]); + QueryIntegerProperty(_entities[4].properties[2]); /// see [LogEntry.mmolPerL] static final mmolPerL = - QueryDoubleProperty(_entities[5].properties[3]); + QueryDoubleProperty(_entities[4].properties[3]); /// see [LogEntry.bolusGlucose] static final bolusGlucose = - QueryDoubleProperty(_entities[5].properties[4]); + QueryDoubleProperty(_entities[4].properties[4]); /// see [LogEntry.delayedBolusDuration] static final delayedBolusDuration = - QueryIntegerProperty(_entities[5].properties[5]); + QueryIntegerProperty(_entities[4].properties[5]); /// see [LogEntry.delayedBolusRate] static final delayedBolusRate = - QueryDoubleProperty(_entities[5].properties[6]); + QueryDoubleProperty(_entities[4].properties[6]); /// see [LogEntry.notes] static final notes = - QueryStringProperty(_entities[5].properties[7]); + QueryStringProperty(_entities[4].properties[7]); } /// [LogEvent] entity fields to define ObjectBox queries. class LogEvent_ { /// see [LogEvent.id] - static final id = QueryIntegerProperty(_entities[6].properties[0]); + static final id = QueryIntegerProperty(_entities[5].properties[0]); /// see [LogEvent.time] static final time = - QueryIntegerProperty(_entities[6].properties[1]); + QueryIntegerProperty(_entities[5].properties[1]); /// see [LogEvent.endTime] static final endTime = - QueryIntegerProperty(_entities[6].properties[2]); + QueryIntegerProperty(_entities[5].properties[2]); /// see [LogEvent.hasEndTime] static final hasEndTime = - QueryBooleanProperty(_entities[6].properties[3]); + QueryBooleanProperty(_entities[5].properties[3]); /// see [LogEvent.notes] static final notes = - QueryStringProperty(_entities[6].properties[4]); + QueryStringProperty(_entities[5].properties[4]); /// see [LogEvent.logEntry] static final logEntry = - QueryRelationToOne(_entities[6].properties[5]); + QueryRelationToOne(_entities[5].properties[5]); /// see [LogEvent.endLogEntry] static final endLogEntry = - QueryRelationToOne(_entities[6].properties[6]); + QueryRelationToOne(_entities[5].properties[6]); /// see [LogEvent.eventType] static final eventType = - QueryRelationToOne(_entities[6].properties[7]); + QueryRelationToOne(_entities[5].properties[7]); } /// [LogEventType] entity fields to define ObjectBox queries. class LogEventType_ { /// see [LogEventType.id] static final id = - QueryIntegerProperty(_entities[7].properties[0]); + QueryIntegerProperty(_entities[6].properties[0]); /// see [LogEventType.value] static final value = - QueryStringProperty(_entities[7].properties[1]); + QueryStringProperty(_entities[6].properties[1]); /// see [LogEventType.hasEndTime] static final hasEndTime = - QueryBooleanProperty(_entities[7].properties[2]); + QueryBooleanProperty(_entities[6].properties[2]); /// see [LogEventType.defaultReminderDuration] static final defaultReminderDuration = - QueryIntegerProperty(_entities[7].properties[3]); + QueryIntegerProperty(_entities[6].properties[3]); /// see [LogEventType.notes] static final notes = - QueryStringProperty(_entities[7].properties[4]); + QueryStringProperty(_entities[6].properties[4]); } /// [LogMeal] entity fields to define ObjectBox queries. class LogMeal_ { /// see [LogMeal.id] - static final id = QueryIntegerProperty(_entities[8].properties[0]); + static final id = QueryIntegerProperty(_entities[7].properties[0]); /// see [LogMeal.value] - static final value = QueryStringProperty(_entities[8].properties[1]); + static final value = QueryStringProperty(_entities[7].properties[1]); /// see [LogMeal.carbsRatio] static final carbsRatio = - QueryDoubleProperty(_entities[8].properties[2]); + QueryDoubleProperty(_entities[7].properties[2]); /// see [LogMeal.portionSize] static final portionSize = - QueryDoubleProperty(_entities[8].properties[3]); + QueryDoubleProperty(_entities[7].properties[3]); /// see [LogMeal.carbsPerPortion] static final carbsPerPortion = - QueryDoubleProperty(_entities[8].properties[4]); + QueryDoubleProperty(_entities[7].properties[4]); /// see [LogMeal.bolus] - static final bolus = QueryDoubleProperty(_entities[8].properties[5]); + static final bolus = QueryDoubleProperty(_entities[7].properties[5]); /// see [LogMeal.delayedBolusDuration] static final delayedBolusDuration = - QueryIntegerProperty(_entities[8].properties[6]); + QueryIntegerProperty(_entities[7].properties[6]); /// see [LogMeal.delayedBolusRate] static final delayedBolusRate = - QueryDoubleProperty(_entities[8].properties[7]); + QueryDoubleProperty(_entities[7].properties[7]); /// see [LogMeal.notes] - static final notes = QueryStringProperty(_entities[8].properties[8]); + static final notes = QueryStringProperty(_entities[7].properties[8]); /// see [LogMeal.logEntry] static final logEntry = - QueryRelationToOne(_entities[8].properties[9]); + QueryRelationToOne(_entities[7].properties[9]); /// see [LogMeal.meal] static final meal = - QueryRelationToOne(_entities[8].properties[10]); + QueryRelationToOne(_entities[7].properties[10]); /// see [LogMeal.mealSource] static final mealSource = - QueryRelationToOne(_entities[8].properties[11]); + QueryRelationToOne(_entities[7].properties[11]); /// see [LogMeal.mealCategory] static final mealCategory = - QueryRelationToOne(_entities[8].properties[12]); + QueryRelationToOne(_entities[7].properties[12]); /// see [LogMeal.mealPortionType] static final mealPortionType = - QueryRelationToOne(_entities[8].properties[13]); + QueryRelationToOne(_entities[7].properties[13]); /// see [LogMeal.portionSizeAccuracy] static final portionSizeAccuracy = - QueryRelationToOne(_entities[8].properties[14]); + QueryRelationToOne(_entities[7].properties[14]); /// see [LogMeal.carbsRatioAccuracy] static final carbsRatioAccuracy = - QueryRelationToOne(_entities[8].properties[15]); + QueryRelationToOne(_entities[7].properties[15]); } /// [Meal] entity fields to define ObjectBox queries. class Meal_ { /// see [Meal.id] - static final id = QueryIntegerProperty(_entities[9].properties[0]); + static final id = QueryIntegerProperty(_entities[8].properties[0]); /// see [Meal.value] - static final value = QueryStringProperty(_entities[9].properties[1]); + static final value = QueryStringProperty(_entities[8].properties[1]); /// see [Meal.carbsRatio] static final carbsRatio = - QueryDoubleProperty(_entities[9].properties[2]); + QueryDoubleProperty(_entities[8].properties[2]); /// see [Meal.portionSize] static final portionSize = - QueryDoubleProperty(_entities[9].properties[3]); + QueryDoubleProperty(_entities[8].properties[3]); /// see [Meal.carbsPerPortion] static final carbsPerPortion = - QueryDoubleProperty(_entities[9].properties[4]); + QueryDoubleProperty(_entities[8].properties[4]); /// see [Meal.delayedBolusDuration] static final delayedBolusDuration = - QueryIntegerProperty(_entities[9].properties[5]); + QueryIntegerProperty(_entities[8].properties[5]); /// see [Meal.delayedBolusRate] static final delayedBolusRate = - QueryDoubleProperty(_entities[9].properties[6]); + QueryDoubleProperty(_entities[8].properties[6]); /// see [Meal.notes] - static final notes = QueryStringProperty(_entities[9].properties[7]); + static final notes = QueryStringProperty(_entities[8].properties[7]); /// see [Meal.mealSource] static final mealSource = - QueryRelationToOne(_entities[9].properties[8]); + QueryRelationToOne(_entities[8].properties[8]); /// see [Meal.mealCategory] static final mealCategory = - QueryRelationToOne(_entities[9].properties[9]); + QueryRelationToOne(_entities[8].properties[9]); /// see [Meal.mealPortionType] static final mealPortionType = - QueryRelationToOne(_entities[9].properties[10]); + QueryRelationToOne(_entities[8].properties[10]); /// see [Meal.portionSizeAccuracy] static final portionSizeAccuracy = - QueryRelationToOne(_entities[9].properties[11]); + QueryRelationToOne(_entities[8].properties[11]); /// see [Meal.carbsRatioAccuracy] static final carbsRatioAccuracy = - QueryRelationToOne(_entities[9].properties[12]); + QueryRelationToOne(_entities[8].properties[12]); } /// [MealCategory] entity fields to define ObjectBox queries. class MealCategory_ { /// see [MealCategory.id] static final id = - QueryIntegerProperty(_entities[10].properties[0]); + QueryIntegerProperty(_entities[9].properties[0]); /// see [MealCategory.value] static final value = - QueryStringProperty(_entities[10].properties[1]); + QueryStringProperty(_entities[9].properties[1]); /// see [MealCategory.notes] static final notes = - QueryStringProperty(_entities[10].properties[2]); + QueryStringProperty(_entities[9].properties[2]); } /// [MealPortionType] entity fields to define ObjectBox queries. class MealPortionType_ { /// see [MealPortionType.id] static final id = - QueryIntegerProperty(_entities[11].properties[0]); + QueryIntegerProperty(_entities[10].properties[0]); /// see [MealPortionType.value] static final value = - QueryStringProperty(_entities[11].properties[1]); + QueryStringProperty(_entities[10].properties[1]); /// see [MealPortionType.notes] static final notes = - QueryStringProperty(_entities[11].properties[2]); + QueryStringProperty(_entities[10].properties[2]); } /// [MealSource] entity fields to define ObjectBox queries. class MealSource_ { /// see [MealSource.id] static final id = - QueryIntegerProperty(_entities[12].properties[0]); + QueryIntegerProperty(_entities[11].properties[0]); /// see [MealSource.value] static final value = - QueryStringProperty(_entities[12].properties[1]); + QueryStringProperty(_entities[11].properties[1]); /// see [MealSource.notes] static final notes = - QueryStringProperty(_entities[12].properties[2]); + QueryStringProperty(_entities[11].properties[2]); /// see [MealSource.defaultMealCategory] static final defaultMealCategory = - QueryRelationToOne(_entities[12].properties[3]); + QueryRelationToOne(_entities[11].properties[3]); /// see [MealSource.defaultMealPortionType] static final defaultMealPortionType = QueryRelationToOne( - _entities[12].properties[4]); + _entities[11].properties[4]); /// see [MealSource.defaultCarbsRatioAccuracy] static final defaultCarbsRatioAccuracy = - QueryRelationToOne(_entities[12].properties[5]); + QueryRelationToOne(_entities[11].properties[5]); /// see [MealSource.defaultPortionSizeAccuracy] static final defaultPortionSizeAccuracy = - QueryRelationToOne(_entities[12].properties[6]); + QueryRelationToOne(_entities[11].properties[6]); +} + +/// [LogBolus] entity fields to define ObjectBox queries. +class LogBolus_ { + /// see [LogBolus.id] + static final id = QueryIntegerProperty(_entities[12].properties[0]); + + /// see [LogBolus.units] + static final units = + QueryDoubleProperty(_entities[12].properties[1]); + + /// see [LogBolus.carbs] + static final carbs = + QueryDoubleProperty(_entities[12].properties[2]); + + /// see [LogBolus.delay] + static final delay = + QueryIntegerProperty(_entities[12].properties[3]); + + /// see [LogBolus.mgPerDl] + static final mgPerDl = + QueryIntegerProperty(_entities[12].properties[4]); + + /// see [LogBolus.mmolPerL] + static final mmolPerL = + QueryDoubleProperty(_entities[12].properties[5]); + + /// see [LogBolus.setManually] + static final setManually = + QueryBooleanProperty(_entities[12].properties[6]); + + /// see [LogBolus.notes] + static final notes = + QueryStringProperty(_entities[12].properties[7]); + + /// see [LogBolus.logEntry] + static final logEntry = + QueryRelationToOne(_entities[12].properties[8]); + + /// see [LogBolus.rate] + static final rate = + QueryRelationToOne(_entities[12].properties[9]); + + /// see [LogBolus.meal] + static final meal = + QueryRelationToOne(_entities[12].properties[10]); +} + +/// [Accuracy] entity fields to define ObjectBox queries. +class Accuracy_ { + /// see [Accuracy.id] + static final id = QueryIntegerProperty(_entities[13].properties[0]); + + /// see [Accuracy.value] + static final value = + QueryStringProperty(_entities[13].properties[1]); + + /// see [Accuracy.forCarbsRatio] + static final forCarbsRatio = + QueryBooleanProperty(_entities[13].properties[2]); + + /// see [Accuracy.forPortionSize] + static final forPortionSize = + QueryBooleanProperty(_entities[13].properties[3]); + + /// see [Accuracy.confidenceRating] + static final confidenceRating = + QueryIntegerProperty(_entities[13].properties[4]); + + /// see [Accuracy.notes] + static final notes = + QueryStringProperty(_entities[13].properties[5]); } diff --git a/lib/screens/log/log.dart b/lib/screens/log/log.dart index 25176c2..8ec7bd2 100644 --- a/lib/screens/log/log.dart +++ b/lib/screens/log/log.dart @@ -74,8 +74,8 @@ class _LogScreenState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( - child: SingleChildScrollView( - child: _logEntryDailyMap.isNotEmpty ? ListView.builder( + child: _logEntryDailyMap.isNotEmpty ? SingleChildScrollView( + child: ListView.builder( shrinkWrap: true, padding: const EdgeInsets.all(10.0), itemCount: _logEntryDailyMap.length, @@ -134,10 +134,10 @@ class _LogScreenState extends State { ], ); }, - ) : const Center( + ), + ) : const Center( child: Text('You have not created any Log Entries yet!'), ), - ), ), ], ), diff --git a/lib/screens/log/log_entry/log_bolus_detail.dart b/lib/screens/log/log_entry/log_bolus_detail.dart index cacdd9c..0f225ca 100644 --- a/lib/screens/log/log_entry/log_bolus_detail.dart +++ b/lib/screens/log/log_entry/log_bolus_detail.dart @@ -40,7 +40,7 @@ class _LogBolusDetailScreenState extends State { final _delayController = TextEditingController(text: ''); final _notesController = TextEditingController(text: ''); - bool _manuallyAdjusted = false; + bool _setManually = false; LogMeal? _meal; Bolus? _rate; @@ -61,10 +61,12 @@ class _LogBolusDetailScreenState extends State { _mmolPerLController.text = (_logBolus!.mmolPerL ?? '').toString(); _delayController.text = (_logBolus!.delay ?? '').toString(); _notesController.text = _logBolus!.notes ?? ''; - _manuallyAdjusted = _logBolus!.manuallyAdjusted; + _setManually = _logBolus!.setManually; _meal = _logBolus!.meal.target; - _rate = _logBolus!.rate.target ?? Bolus.getRateForTime(_logEntry?.time); + _rate = _logBolus!.rate.target; } + + _rate ??= Bolus.getRateForTime(_logEntry?.time); } void reload() { @@ -76,17 +78,22 @@ class _LogBolusDetailScreenState extends State { _isNew = _logBolus == null; } - Future onSelectMeal(LogMeal meal) async { + void onSelectMeal(LogMeal meal) { setState(() { _meal = meal; if (meal.carbsPerPortion != null) { _carbsController.text = meal.carbsPerPortion.toString(); + onChangeCarbs(); + } + }); + } - if (_rate != null) { - _unitsController.text = - (meal.carbsPerPortion ?? 0 / (_rate!.carbs / _rate!.units)) - .toString(); - } + void onChangeCarbs() { + setState(() { + if (_rate != null && !_setManually) { + _unitsController.text = + ((double.tryParse(_carbsController.text) ?? 0) / (_rate!.carbs / _rate!.units)) + .toString(); } }); } @@ -103,7 +110,7 @@ class _LogBolusDetailScreenState extends State { mgPerDl: int.tryParse(_mgPerDlController.text), mmolPerL: double.tryParse(_mmolPerLController.text), delay: int.tryParse(_delayController.text), - manuallyAdjusted: _manuallyAdjusted, + setManually: _setManually, notes: _notesController.text, ); logBolus.logEntry.target = _logEntry; @@ -125,15 +132,18 @@ class _LogBolusDetailScreenState extends State { _mgPerDlController.text != '' || _mmolPerLController.text != '' || _delayController.text != '' || - _manuallyAdjusted || + _setManually || _notesController.text != '')) || (!_isNew && (double.tryParse(_unitsController.text) != _logBolus!.units || - double.tryParse(_carbsController.text) != _logBolus!.carbs || - int.tryParse(_mgPerDlController.text) != _logBolus!.mgPerDl || - double.tryParse(_mmolPerLController.text) != _logBolus!.mmolPerL || + double.tryParse(_carbsController.text) != + _logBolus!.carbs || + int.tryParse(_mgPerDlController.text) != + _logBolus!.mgPerDl || + double.tryParse(_mmolPerLController.text) != + _logBolus!.mmolPerL || int.tryParse(_delayController.text) != _logBolus!.delay || - _manuallyAdjusted != _logBolus!.manuallyAdjusted || + _setManually != _logBolus!.setManually || _notesController.text != (_logBolus!.notes ?? ''))))) { Dialogs.showCancelConfirmationDialog( context: context, @@ -165,9 +175,23 @@ class _LogBolusDetailScreenState extends State { suffixText: ' U', ), controller: _unitsController, + onChanged: (_) { + setState(() { + _setManually = true; + }); + }, keyboardType: const TextInputType.numberWithOptions(decimal: true), ), + BooleanFormField( + value: _setManually, + label: 'set Bolus manually', + onChanged: (value) { + setState(() { + _setManually = value; + }); + }, + ), AutoCompleteDropdownButton( selectedItem: _meal, label: 'Meal', @@ -179,23 +203,21 @@ class _LogBolusDetailScreenState extends State { } }, ), - Expanded( - child: TextFormField( - decoration: InputDecoration( - labelText: 'Carbs', - suffixText: - nutritionMeasurement == NutritionMeasurement.grams - ? 'g' - : nutritionMeasurement == - NutritionMeasurement.ounces - ? 'oz' - : '', - ), - controller: _carbsController, - keyboardType: const TextInputType.numberWithOptions( - decimal: true), - ), - ), + TextFormField( + decoration: InputDecoration( + labelText: 'Carbs', + suffixText: nutritionMeasurement == + NutritionMeasurement.grams + ? 'g' + : nutritionMeasurement == NutritionMeasurement.ounces + ? 'oz' + : '', + ), + controller: _carbsController, + onChanged: (_) => onChangeCarbs(), + keyboardType: + const TextInputType.numberWithOptions(decimal: true), + ), TextFormField( decoration: const InputDecoration( labelText: 'Delayed Bolus Duration', diff --git a/lib/screens/log/log_entry/log_event_detail.dart b/lib/screens/log/log_entry/log_event_detail.dart index d151eb4..5142e70 100644 --- a/lib/screens/log/log_entry/log_event_detail.dart +++ b/lib/screens/log/log_entry/log_event_detail.dart @@ -71,6 +71,7 @@ class _LogEventDetailScreenState extends State { hasEndTime: _hasEndTime, notes: _notesController.text, ); + event.logEntry.targetId = widget.logEntryId; event.eventType.target = _eventType; LogEvent.put(event); Navigator.pop(context, '${_isNew ? 'New' : ''} Event Saved'); diff --git a/lib/screens/log/log_entry/log_meal_detail.dart b/lib/screens/log/log_entry/log_meal_detail.dart index ca62274..ae8bcbb 100644 --- a/lib/screens/log/log_entry/log_meal_detail.dart +++ b/lib/screens/log/log_entry/log_meal_detail.dart @@ -148,6 +148,7 @@ class _LogMealDetailScreenState extends State { delayedBolusRate: double.tryParse(_delayedBolusRateController.text), notes: _notesController.text, ); + logMeal.logEntry.targetId = widget.logEntryId; logMeal.meal.target = _meal; logMeal.mealSource.target = _mealSource; logMeal.mealCategory.target = _mealCategory; @@ -197,8 +198,7 @@ class _LogMealDetailScreenState extends State { _logMeal!.carbsRatioAccuracy.target || _portionSizeAccuracy != _logMeal!.portionSizeAccuracy.target || - double.tryParse(_bolusController.text) != - _logMeal!.bolus || + double.tryParse(_bolusController.text) != _logMeal!.bolus || int.tryParse(_delayedBolusDurationController.text) != _logMeal!.delayedBolusDuration || double.tryParse(_delayedBolusRateController.text) !=