Commit d18d8dc

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 076c9c4
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
@@ -45,6 +45,7 @@ class Settings extends ChangeNotifier {
     List<Medicine>? medications,
     List<String>? knownBleDev,
     int? highestMedIndex,
+    bool? bleInput,
   }) {
     if (accentColor != null) _accentColor = accentColor;
     if (sysColor != null) _sysColor = sysColor;
@@ -70,6 +71,7 @@ class Settings extends ChangeNotifier {
     if (medications != null) _medications.addAll(medications);
     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.
   }
 
@@ -103,6 +105,7 @@ class Settings extends ChangeNotifier {
           Medicine.fromJson(jsonDecode(e)),).toList(),
       highestMedIndex: ConvertUtil.parseInt(map['highestMedIndex']),
       knownBleDev: ConvertUtil.parseList<String>(map['knownBleDev']),
+      bleInput: ConvertUtil.parseBool(map['bleInput']),
     );
 
     // update
@@ -148,6 +151,7 @@ class Settings extends ChangeNotifier {
       'medications': medications.map(jsonEncode).toList(),
       'highestMedIndex': highestMedIndex,
       'knownBleDev': knownBleDev,
+      'bleInput': bleInput,
     };
 
   /// Serialize the object to a restoreable string.
@@ -345,6 +349,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
@@ -168,6 +168,13 @@ class SettingsPage extends StatelessWidget {
                 },
                 secondary: const Icon(Icons.details),
                 title: Text(localizations.allowManualTimeInput),),
+              SwitchListTile(
+                value: settings.bleInput,
+                onChanged: (value) {
+                  settings.bleInput = value;
+                },
+                secondary: const Icon(Icons.bluetooth),
+                title: Text(localizations.bluetoothInput),),
               SwitchListTile(
                 key: const Key('validateInputs'),
                 value: settings.validateInputs,
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());
     });