Commit 8b1a2c6

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-05-18 16:59:07
make ble input toggleable in settings
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 4723a55
Changed files (4)
app/lib/components/dialoges/add_measurement_dialoge.dart
@@ -281,11 +281,11 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
         child: ListView(
           padding: const EdgeInsets.symmetric(horizontal: 8),
           children: [
-            // TODO: make toggleable in settings
-            BluetoothInput(
-              settings: widget.settings,
-              onMeasurement: (record) => setState(() => _loadFields(record)),
-            ),
+            if (widget.settings.bleInput)
+              BluetoothInput(
+                settings: widget.settings,
+                onMeasurement: (record) => setState(() => _loadFields(record)),
+              ),
             if (widget.settings.allowManualTimeInput)
               _buildTimeInput(localizations),
             Form(
app/lib/model/storage/settings_store.dart
@@ -47,6 +47,7 @@ class Settings extends ChangeNotifier {
     PressureUnit? preferredPressureUnit,
     List<String>? knownBleDev,
     int? highestMedIndex,
+    bool? bleInput,
   }) {
     if (accentColor != null) _accentColor = accentColor;
     if (sysColor != null) _sysColor = sysColor;
@@ -73,6 +74,7 @@ class Settings extends ChangeNotifier {
     if (preferredPressureUnit != null) _preferredPressureUnit = preferredPressureUnit;
     if (highestMedIndex != null) _highestMedIndex = highestMedIndex;
     if (knownBleDev != null) _knownBleDev = knownBleDev;
+    if (bleInput != null) _bleInput = bleInput;
     _language = language; // No check here, as null is the default as well.
   }
 
@@ -105,6 +107,8 @@ class Settings extends ChangeNotifier {
       medications: ConvertUtil.parseList<String>(map['medications'])?.map((e) =>
           Medicine.fromJson(jsonDecode(e)),).toList(),
       highestMedIndex: ConvertUtil.parseInt(map['highestMedIndex']),
+      knownBleDev: ConvertUtil.parseList<String>(map['knownBleDev']),
+      bleInput: ConvertUtil.parseBool(map['bleInput']),
     );
 
     // update
@@ -151,6 +155,7 @@ class Settings extends ChangeNotifier {
       'highestMedIndex': highestMedIndex,
       'preferredPressureUnit': preferredPressureUnit.encode(),
       'knownBleDev': knownBleDev,
+      'bleInput': bleInput,
     };
 
   /// Serialize the object to a restoreable string.
@@ -356,6 +361,14 @@ class Settings extends ChangeNotifier {
     notifyListeners();
   }
 
+  bool _bleInput = true;
+  /// Whether to show bluetooth input on add measurement page.
+  bool get bleInput => _bleInput;
+  set bleInput(bool value) {
+    _bleInput = value;
+    notifyListeners();
+  }
+
   List<String> _knownBleDev = [];
   /// Bluetooth devices that previously connected.
   ///
app/lib/screens/settings_screen.dart
@@ -44,8 +44,8 @@ class SettingsPage extends StatelessWidget {
           children: [
             TitledColumn(title: Text(localizations.layout), children: [
               ListTile(
-                title: Text(localizations.enterTimeFormatScreen),
                 key: const Key('EnterTimeFormatScreen'),
+                title: Text(localizations.enterTimeFormatScreen),
                 subtitle: Text(settings.dateFormatString),
                 leading: const Icon(Icons.schedule),
                 trailing: const Icon(Icons.arrow_forward_ios),
app/test/model/json_serialization_test.dart
@@ -97,6 +97,7 @@ void main() {
         bottomAppBars: true,
         medications: [mockMedicine(), mockMedicine(defaultDosis: 42)],
         knownBleDev: ['a', 'b'],
+        bleInput: false,
       );
       final fromJson = Settings.fromJson(initial.toJson());
 
@@ -124,6 +125,7 @@ void main() {
       expect(initial.needlePinBarWidth, fromJson.needlePinBarWidth);
       expect(initial.bottomAppBars, fromJson.bottomAppBars);
       expect(initial.knownBleDev, fromJson.knownBleDev);
+      expect(initial.bleInput, fromJson.bleInput);
 
       expect(initial.toJson(), fromJson.toJson());
     });