Commit 78551e0

derdilla <derdilla06@gmail.com>
2023-07-27 10:01:40
add regression line setting
1 parent eadaace
lib/components/measurement_graph.dart
@@ -85,9 +85,12 @@ class _LineChartState extends State<_LineChart> {
                                   _buildBarData(value, sysSpots, settings.sysColor, true, settings.sysWarn.toDouble()),
                                   _buildBarData(value, diaSpots, settings.diaColor, true, settings.diaWarn.toDouble()),
                                   _buildBarData(value, pulSpots, settings.pulColor, false),
-                                  _buildRegressionLine(sysSpots),
-                                  _buildRegressionLine(diaSpots),
-                                  _buildRegressionLine(pulSpots),
+                                  if (settings.drawRegressionLines)
+                                    _buildRegressionLine(sysSpots),
+                                  if (settings.drawRegressionLines)
+                                    _buildRegressionLine(diaSpots),
+                                  if (settings.drawRegressionLines)
+                                    _buildRegressionLine(pulSpots),
                                 ]
                             ),
                             duration: const Duration(milliseconds: 200),
lib/components/settings_widgets.dart
@@ -32,34 +32,37 @@ class SettingsTile extends StatelessWidget {
 
     return InkWell(
       onTap: () => onPressed(context),
-      child: SizedBox(
-        height: 48,
+      child: ConstrainedBox(
+        constraints: BoxConstraints(minHeight: 48, maxWidth: MediaQuery.of(context).size.width),
         child: Row(
+          mainAxisSize: MainAxisSize.min,
           children: [
             lead,
             const SizedBox(
               width: 15,
             ),
-            SizedBox(
-              child: (() {
-                if (description != null) {
-                  return Column(
+            if (description != null)
+              Expanded(
+                flex: 10,
+                child: Container(
+                  padding: const EdgeInsets.only(top: 5, bottom: 5),
+                  child: Column(
                     mainAxisSize: MainAxisSize.min,
                     crossAxisAlignment: CrossAxisAlignment.start,
                     children: [
                       title,
-                      Flexible(
-                          child: DefaultTextStyle(
-                              style: const TextStyle(color: Colors.grey),
-                              overflow: TextOverflow.visible,
-                              child: description ?? const SizedBox.shrink()))
+                      DefaultTextStyle(
+                          style: const TextStyle(color: Colors.grey, ),
+                          child: description ?? const SizedBox.shrink()
+                      )
                     ],
-                  );
-                }
-                return title;
-              })(),
-            ),
-            const Expanded(child: SizedBox.shrink()),
+                  ),
+                ),
+              ),
+            if (description == null)
+              title,
+            const Spacer(),
+            //const Expanded(child: SizedBox.shrink()),
             trail
           ],
         ),
lib/l10n/app_en.arb
@@ -339,5 +339,7 @@
   "@allowMissingValues": {},
   "errTimeAfterNow": "The selected time of day is after this moment. We have automatically reset it to the current time. You can disable this validation in the settings!",
   "language": "Language",
-  "custom": "Custom"
+  "custom": "Custom",
+  "drawRegressionLines": "Draw trend lines",
+  "drawRegressionLinesDesc": "Draws regression lines in graph. Only useful for large intervalls."
 }
lib/model/ram_only_implementations.dart
@@ -71,6 +71,7 @@ class RamSettings extends ChangeNotifier implements Settings {
   bool _exportAfterEveryEntry = false;
   bool _allowMissingValues = false;
   Locale? _language;
+  bool _drawRegressionLines = false;
 
   RamSettings() {
     _accentColor = createMaterialColor(0xFF009688);
@@ -381,6 +382,15 @@ class RamSettings extends ChangeNotifier implements Settings {
     notifyListeners();
   }
 
+  @override
+  bool get drawRegressionLines => _drawRegressionLines;
+
+  @override
+  set drawRegressionLines(bool value) {
+    _drawRegressionLines = value;
+    notifyListeners();
+  }
+
   @override
   void changeStepSize(TimeStep value) {
     graphStepSize = value;
lib/model/settings_store.dart
@@ -497,6 +497,15 @@ class Settings extends ChangeNotifier {
     _prefs.setString('language', value?.languageCode ?? '');
     notifyListeners();
   }
+
+  bool get drawRegressionLines {
+    return _prefs.getBool('drawRegressionLines') ?? false;
+  }
+
+  set drawRegressionLines(bool value) {
+    _prefs.setBool('drawRegressionLines', value);
+    notifyListeners();
+  }
 }
 
 enum TimeStep {
lib/screens/settings.dart
@@ -244,6 +244,15 @@ class SettingsPage extends StatelessWidget {
                   );
                 }
               ),
+              SwitchSettingsTile(
+                  title: Text(AppLocalizations.of(context)!.drawRegressionLines),
+                  leading: const Icon(Icons.trending_down_outlined),
+                  description: Text(AppLocalizations.of(context)!.drawRegressionLinesDesc),
+                  initialValue: settings.drawRegressionLines,
+                  onToggle: (value) {
+                    settings.drawRegressionLines = value;
+                  }
+              ),
             ]),
             SettingsSection(
               title: Text(AppLocalizations.of(context)!.data),