Commit 3472879

derdilla <derdilla06@gmail.com>
2023-05-13 16:45:50
FEAT: icon size settings
1 parent 546857f
Changed files (5)
lib/components/complex_settings.dart
@@ -13,7 +13,7 @@ class SettingsTile extends StatelessWidget {
 
   @override
   Widget build(BuildContext context) {
-    if (disabled) return SizedBox.shrink();
+    if (disabled) return const SizedBox.shrink();
 
     var lead = SizedBox(
       width: 40,
@@ -143,6 +143,94 @@ class SwitchSettingsTile extends StatelessWidget {
   }
 }
 
+class SliderSettingsTile extends StatefulWidget {
+  final Widget title;
+  final void Function(double newValue) onChanged;
+  final Widget? leading;
+  final Widget? description;
+  final Widget? trailing;
+  final bool disabled;
+  final double start;
+  final double end;
+  final double stepSize;
+  final double initialValue;
+
+  const SliderSettingsTile({
+    super.key,
+    required this.title,
+    required this.onChanged,
+    required this.initialValue,
+    required this.start,
+    required this.end,
+    this.stepSize = 1,
+    this.description,
+    this.leading,
+    this.trailing,
+    this.disabled = false});
+
+  @override
+  State<StatefulWidget> createState() => _SliderSettingsTileState(initialValue);
+}
+
+class _SliderSettingsTileState extends State<SliderSettingsTile> {
+  double _value;
+
+  _SliderSettingsTileState(this._value);
+
+  @override
+  Widget build(BuildContext context) {
+    if (widget.disabled) return const SizedBox.shrink();
+
+    var lead = SizedBox(
+      width: 40,
+      child: widget.leading ?? const SizedBox.shrink(),
+    );
+    var trail = widget.trailing ?? const SizedBox.shrink();
+
+    return SizedBox(
+      height: 70,
+      child: Row(
+        children: [
+          lead,
+          SizedBox(
+            width: MediaQuery.of(context).size.width - 150,
+            child: Column(
+              mainAxisSize: MainAxisSize.min,
+              crossAxisAlignment: CrossAxisAlignment.start,
+              children: [
+                widget.title,
+                Flexible(
+                    child: DefaultTextStyle(
+                        style: const TextStyle(color: Colors.grey),
+                        overflow: TextOverflow.visible,
+                        child: widget.description ?? const SizedBox.shrink()
+                    )
+                ),
+                Expanded(
+                    child: Slider(
+                      value: _value,
+                      onChanged: (newValue) {
+                        setState(() {
+                          _value = newValue;
+                        });
+                        widget.onChanged(newValue);
+                      },
+                      min: widget.start,
+                      max: widget.end,
+                      divisions: (widget.end-widget.start)~/widget.stepSize,
+                    )
+                )
+              ],
+            ),
+          ),
+          const Expanded(child: SizedBox.shrink()),
+          trail
+        ],
+      ),
+    );
+  }
+}
+
 class SettingsSection extends StatelessWidget {
   final Widget title;
   final List<Widget> children;
lib/model/settings.dart
@@ -120,6 +120,13 @@ class Settings extends ChangeNotifier {
     _prefs.setBool('useExportCompatability', useExportCompatability);
     notifyListeners();
   }
+  double get iconSize {
+    return _prefs.getInt('iconSize')?.toDouble() ?? 30;
+  }
+  set iconSize(double newSize) {
+    _prefs.setInt('iconSize', newSize.toInt());
+    notifyListeners();
+  }
 
 }
 
lib/screens/home.dart
@@ -1,9 +1,12 @@
+import 'package:blood_pressure_app/model/settings.dart';
 import 'package:blood_pressure_app/screens/add_measurement.dart';
 import 'package:blood_pressure_app/screens/settings.dart';
 import 'package:flutter/material.dart';
 import 'package:blood_pressure_app/components/measurement_graph.dart';
 import 'package:blood_pressure_app/components/measurement_list.dart';
 import 'package:flutter/services.dart';
+import 'package:provider/provider.dart';
+
 
 class AppHome extends StatelessWidget {
   const AppHome({super.key});
@@ -41,56 +44,60 @@ class AppHome extends StatelessWidget {
       ),
       floatingActionButton: OrientationBuilder(
         builder: (context, orientation) {
-          if (orientation == Orientation.landscape) {
+          if (orientation == Orientation.landscape && MediaQuery.of(context).size.height < 500) {
             SystemChrome.setEnabledSystemUIMode(SystemUiMode.leanBack);
             return const SizedBox.shrink();
           }
           SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
-          return SizedBox(
-            height: 150,
-            child: Column(
-              verticalDirection: VerticalDirection.up,
-              children: [
-                Ink(
-                  decoration: ShapeDecoration(
-                      shape: const CircleBorder(),
-                      color: Theme.of(context).primaryColor
-                  ),
-                  child: IconButton(
-                    icon: const Icon(
-                      Icons.add,
-                      color: Colors.black,
+          return Consumer<Settings>(
+            builder: (context, settings, child) {
+              return SizedBox(
+                child: Column(
+                  verticalDirection: VerticalDirection.up,
+                  children: [
+                    Ink(
+                      decoration: ShapeDecoration(
+                          shape: const CircleBorder(),
+                          color: Theme.of(context).primaryColor
+                      ),
+                      child: IconButton(
+                        iconSize: settings.iconSize,
+                        icon: const Icon(
+                          Icons.add,
+                          color: Colors.black,
+                        ),
+                        onPressed: () {
+                          Navigator.push(
+                            context,
+                            MaterialPageRoute(builder: (context) => const AddMeasurementPage()),
+                          );
+                        },
+                      ),
                     ),
-                    onPressed: () {
-                      Navigator.push(
-                        context,
-                        MaterialPageRoute(builder: (context) => const AddMeasurementPage()),
-                      );
-                    },
-                  ),
-                ),
-                const SizedBox(height: 10,),
-                Ink(
-                  decoration: ShapeDecoration(
-                      shape: const CircleBorder(),
-                      color: Theme.of(context).unselectedWidgetColor
-                  ),
-                  child: IconButton(
-                    icon: const Icon(
-                        Icons.settings,
-                        color: Colors.black
+                    const SizedBox(height: 10,),
+                    Ink(
+                      decoration: ShapeDecoration(
+                          shape: const CircleBorder(),
+                          color: Theme.of(context).unselectedWidgetColor
+                      ),
+                      child: IconButton(
+                        iconSize: settings.iconSize,
+                        icon: const Icon(
+                            Icons.settings,
+                            color: Colors.black
+                        ),
+                        onPressed: () {
+                          Navigator.push(
+                            context,
+                            MaterialPageRoute(builder: (context) => const SettingsPage()),
+                          );
+                        },
+                      ),
                     ),
-                    onPressed: () {
-                      Navigator.push(
-                        context,
-                        MaterialPageRoute(builder: (context) => const SettingsPage()),
-                      );
-                    },
-                  ),
+                  ],
                 ),
-
-              ],
-            ),
+              );
+            }
           );
         })
     );
lib/screens/settings.dart
@@ -39,7 +39,7 @@ class SettingsPage extends StatelessWidget {
                           onPressed: (context) {
                             Navigator.push(
                               context,
-                              MaterialPageRoute(builder: (context) => EnterTimeFormatScreen()),
+                              MaterialPageRoute(builder: (context) => const EnterTimeFormatScreen()),
                             );
                           },
                         ),
@@ -65,7 +65,15 @@ class SettingsPage extends StatelessWidget {
                           title: const Text('enable dark mode'),
                           disabled: settings.followSystemDarkMode,
                         ),
-                        //settings.accentColor = settings.createMaterialColor((color ?? Colors.teal).value);
+                        SliderSettingsTile(title: const Text('icon size'),
+                            onChanged: (double value) {
+                              settings.iconSize = value;
+                            },
+                            initialValue: settings.iconSize,
+                            start: 15,
+                            end: 70,
+                            stepSize: 5,
+                        ),
                         ColorSelectionSettingsTile(
                             onMainColorChanged: (color) => settings.accentColor = settings.createMaterialColor((color ?? Colors.teal).value),
                             initialColor: settings.accentColor,
test/model/settings_test.dart
@@ -37,6 +37,7 @@ void main() {
       expect(s.allowManualTimeInput, true);
       expect(s.dateFormatString, 'yy-MM-dd H:mm');
       expect(s.useExportCompatability, false);
+      expect(s.iconSize, 30);
     });
 
     test('setting fields should save changes', () async {
@@ -65,6 +66,7 @@ void main() {
       s.allowManualTimeInput = false;
       s.dateFormatString = 'yy:dd @ H:mm.ss';
       s.useExportCompatability = true;
+      s.iconSize = 50;
 
 
       expect(s.graphStart, DateTime.fromMillisecondsSinceEpoch(10000));
@@ -77,6 +79,7 @@ void main() {
       expect(s.pulColor.value, 0xFF942DA7);
       expect(s.allowManualTimeInput, false);
       expect(s.useExportCompatability, true);
+      expect(s.iconSize, 50);
     });
 
     test('setting fields should notify listeners and change values', () async {
@@ -99,8 +102,9 @@ void main() {
       s.allowManualTimeInput = false;
       s.dateFormatString = 'yy:dd @ H:mm.ss';
       s.useExportCompatability = true;
+      s.iconSize = 10;
       
-      expect(i, 12);
+      expect(i, 13);
     });
 
   });