Commit 0e4d797

derdilla <derdilla06@gmail.com>
2023-06-16 13:55:38
add structure for export page
1 parent a80780b
lib/l10n/app_de.arb
@@ -52,8 +52,10 @@
   "layout": "Layout",
   "allowManualTimeInput": "Editierbare Zeitangaben",
   "enterTimeFormatScreen": "Datums-/Zeitformat",
-  "followSystemDarkMode": "Thema wie System",
-  "darkMode": "Dunkles Thema",
+  "theme": "Thema",
+  "system": "System",
+  "dark": "Dunkel",
+  "light": "Hell",
   "iconSize": "Größe der Knöpfe",
   "graphLineThickness": "Linienstärke d. Graphen",
   "animationSpeed": "Animationsdauer",
@@ -73,6 +75,10 @@
   "sysWarn": "Warnwert Sys",
   "diaWarn": "Warnwert Dia",
   "data": "Daten",
+  "exportImport": "Exportieren / Importieren",
+  "exportFormat": "Exportformat",
+  "csv": "csv",
+  "pdf": "pdf",
   "useExportCompatability": "Kompatibler Export",
   "useExportCompatabilityDesc": "Signalisiert Export als Text",
   "export": "Exportieren",
lib/l10n/app_en.arb
@@ -52,8 +52,10 @@
   "layout": "layout",
   "allowManualTimeInput": "allow manual time input",
   "enterTimeFormatScreen": "time format",
-  "followSystemDarkMode": "follow system dark mode",
-  "darkMode": "enable dark mode",
+  "theme": "theme",
+  "system": "System",
+  "dark": "dark",
+  "light": "light",
   "iconSize": "icon size",
   "graphLineThickness": "line thickness",
   "animationSpeed": "animation duration",
@@ -73,6 +75,10 @@
   "sysWarn": "systolic warn",
   "diaWarn": "diastolic warn",
   "data": "data",
+  "exportImport": "export / import",
+  "exportFormat": "export format",
+  "csv": "csv",
+  "pdf": "pdf",
   "useExportCompatability": "compatability export",
   "useExportCompatabilityDesc": "sets export mime type to text",
   "export": "export",
lib/model/export_import.dart
@@ -0,0 +1,41 @@
+
+import 'dart:typed_data';
+
+import 'package:intl/intl.dart';
+
+import 'blood_pressure.dart';
+
+class CSVExportSettings {
+  final DateFormat dateFormatter;
+  final String? fieldDelimiter;
+  final String? textDelimiter;
+  final String? textEndDelimiter;
+
+  CSVExportSettings(this.dateFormatter, this.fieldDelimiter, this.textDelimiter, this.textEndDelimiter);
+}
+
+class ExportFormat {
+  final int code;
+
+  ExportFormat(this.code) {
+    if (code < 0 || code > 1) throw const FormatException('Not a export format');
+  }
+  static ExportFormat csv = ExportFormat(0);
+  static ExportFormat pdf = ExportFormat(1);
+
+  @override
+  bool operator == (Object other) {
+    try {
+      return code == (other as ExportFormat).code;
+    } on Exception {
+      try {
+        return code == (other as int);
+      } on Exception {
+        return false;
+      }
+    }
+  }
+
+  @override
+  int get hashCode => code;
+}
\ No newline at end of file
lib/model/settings_store.dart
@@ -1,4 +1,5 @@
 import 'package:blood_pressure_app/model/blood_pressure.dart';
+import 'package:blood_pressure_app/model/export_import.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_gen/gen_l10n/app_localizations.dart';
 import 'package:shared_preferences/shared_preferences.dart';
@@ -279,6 +280,14 @@ class Settings extends ChangeNotifier {
     _prefs.setInt('titlesCount', newCount);
     notifyListeners();
   }
+
+  ExportFormat get exportFormat {
+    return ExportFormat(_prefs.getInt('exportFormat') ?? 0);
+  }
+  set exportFormat(ExportFormat format) {
+    _prefs.setInt('exportFormat', format.code);
+    notifyListeners();
+  }
 }
 
 class TimeStep {
lib/screens/subsettings/export_import_screen.dart
@@ -0,0 +1,47 @@
+
+import 'package:blood_pressure_app/components/settings_widgets.dart';
+import 'package:blood_pressure_app/model/export_import.dart';
+import 'package:blood_pressure_app/model/settings_store.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+import 'package:provider/provider.dart';
+
+class ExportImportScreen extends StatelessWidget {
+  const ExportImportScreen({super.key});
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      appBar: AppBar(title: Text(AppLocalizations.of(context)!.exportImport),),
+      body: Consumer<Settings>(builder: (context, settings, child) {
+        List<Widget> modeSpecificSettings = [];
+        if (settings.exportFormat == ExportFormat.csv) {
+          modeSpecificSettings = [];
+        }
+
+        List<Widget> options = [
+          DropDownSettingsTile<ExportFormat>(
+            key: const Key('exportFormat'),
+            leading: const Icon(Icons.error),
+            title: Text(AppLocalizations.of(context)!.exportFormat),
+            value: settings.exportFormat,
+            items: [
+              DropdownMenuItem(value: ExportFormat.csv, child: Text(AppLocalizations.of(context)!.csv)),
+              DropdownMenuItem(value: ExportFormat.pdf, child: Text(AppLocalizations.of(context)!.pdf)),
+            ],
+            onChanged: (ExportFormat? value) {
+              if (value != null) {
+                settings.exportFormat = value;
+              }
+            },
+          )
+        ];
+        options.addAll(modeSpecificSettings);
+
+        return ListView(
+          children: options,
+        );
+      }),
+    );
+  }
+}