Commit 201c659

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2023-12-23 10:07:30
warn users that export after every entry to review their export settings
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 5337b09
Changed files (2)
lib/model/storage/settings_store.dart
@@ -26,6 +26,7 @@ class Settings extends ChangeNotifier {
     int? animationSpeed,
     int? sysWarn,
     int? diaWarn,
+    int? lastVersion,
     bool? allowManualTimeInput,
     bool? confirmDeletion,
     ThemeMode? themeMode,
@@ -54,6 +55,7 @@ class Settings extends ChangeNotifier {
     if (startWithAddMeasurementPage != null) _startWithAddMeasurementPage = startWithAddMeasurementPage;
     if (useLegacyList != null) _useLegacyList = useLegacyList;
     if (horizontalGraphLines != null) _horizontalGraphLines = horizontalGraphLines;
+    if (lastVersion != null) _lastVersion = lastVersion;
     _language = language; // No check here, as null is the default as well.
   }
 
@@ -79,7 +81,8 @@ class Settings extends ChangeNotifier {
       language: ConvertUtil.parseLocale(map['language']),
       horizontalGraphLines: ConvertUtil.parseList<String>(map['horizontalGraphLines'])?.map((e) =>
           HorizontalGraphLine.fromJson(jsonDecode(e))).toList(),
-      needlePinBarWidth: ConvertUtil.parseDouble(map['needlePinBarWidth'])
+      needlePinBarWidth: ConvertUtil.parseDouble(map['needlePinBarWidth']),
+      lastVersion: ConvertUtil.parseInt(map['lastVersion'])
     );
 
     // update
@@ -117,7 +120,8 @@ class Settings extends ChangeNotifier {
       'useLegacyList': useLegacyList,
       'language': ConvertUtil.serializeLocale(language),
       'horizontalGraphLines': horizontalGraphLines.map((e) => jsonEncode(e)).toList(),
-      'needlePinBarWidth': _needlePinBarWidth
+      'needlePinBarWidth': _needlePinBarWidth,
+      'lastVersion': lastVersion
     };
 
   String toJson() => jsonEncode(toMap());
@@ -205,6 +209,13 @@ class Settings extends ChangeNotifier {
     notifyListeners();
   }
 
+  int _lastVersion = 0;
+  int get lastVersion => _lastVersion;
+  set lastVersion(int value) {
+    _lastVersion = value;
+    notifyListeners();
+  }
+
   bool _allowManualTimeInput = true;
   bool get allowManualTimeInput => _allowManualTimeInput;
   set allowManualTimeInput(bool value) {
lib/main.dart
@@ -10,6 +10,8 @@ import 'package:blood_pressure_app/screens/loading.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_gen/gen_l10n/app_localizations.dart';
 import 'package:flutter_localizations/flutter_localizations.dart';
+import 'package:fluttertoast/fluttertoast.dart';
+import 'package:package_info_plus/package_info_plus.dart';
 import 'package:provider/provider.dart';
 
 late final ConfigDB _database;
@@ -39,8 +41,18 @@ Future<Widget> _loadApp() async {
   final intervalStorageManager = await IntervallStoreManager.load(configDao, 0);
   final exportColumnsManager = await configDao.loadExportColumnsManager(0);
 
-  await updateLegacySettings(settings, exportSettings, csvExportSettings, pdfExportSettings, intervalStorageManager);
-  await updateLegacyExport(_database, exportColumnsManager);
+  // update logic
+  if (settings.lastVersion == 0) {
+    await updateLegacySettings(settings, exportSettings, csvExportSettings, pdfExportSettings, intervalStorageManager);
+    await updateLegacyExport(_database, exportColumnsManager);
+
+    settings.lastVersion = int.parse((await PackageInfo.fromPlatform()).buildNumber);
+    if (exportSettings.exportAfterEveryEntry) {
+      await Fluttertoast.showToast(
+        msg: r'Please review your export settings to ensure everything works as expected.',
+      );
+    }
+  }
 
   // Reset the step size intervall to current on startup
   intervalStorageManager.mainPage.setToMostRecentIntervall();