Commit 60f9fe0
Changed files (5)
lib
screens
test
model
lib/model/blood_pressure.dart
@@ -108,7 +108,7 @@ class BloodPressureModel extends ChangeNotifier {
return UnmodifiableListView(recordsInRange);
}
- Future<void> save(void Function(bool success, String? msg) callback) async {
+ Future<void> save(void Function(bool success, String? msg) callback, {bool exportAsText = false}) async {
// create csv
String csvData = 'timestampUnixMs, systolic, diastolic, pulse, notes\n';
List<Map<String, Object?>> allEntries = await _database.query('bloodPressureModel',
@@ -130,8 +130,11 @@ class BloodPressureModel extends ChangeNotifier {
if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
callback(true, 'Exported to: $path');
} else if (Platform.isAndroid || Platform.isIOS) {
- // TODO: compatability option (MIME Types)
- Share.shareXFiles([XFile(path, mimeType: MimeType.csv.type,)]);
+ var mimeType = MimeType.csv;
+ if (exportAsText) {
+ mimeType = MimeType.text;
+ }
+ Share.shareXFiles([XFile(path, mimeType: mimeType.type,)]);
callback(true, null);
} else {
lib/model/settings.dart
@@ -22,11 +22,14 @@ class Settings extends ChangeNotifier {
late MaterialColor _pulColor;
late bool _allowManualTimeInput;
late String _dateFormatString;
+ late bool _useExportCompatability;
Settings._create();
- Future<void> _asyncInit() async {
+ Future<void> _asyncInit(String? dbPath) async {
+ dbPath ??= await getDatabasesPath();
+
_database = await openDatabase(
- join(await getDatabasesPath(), 'settings.db'),
+ join(dbPath, 'settings.db'),
// runs when the database is first created
onCreate: (db, version) {
return db.execute('CREATE TABLE settings(key STRING PRIMARY KEY, value STRING)');
@@ -36,7 +39,7 @@ class Settings extends ChangeNotifier {
await _loadSettings();
}
// factory method, to allow for async contructor
- static Future<Settings> create() async {
+ static Future<Settings> create({String? dbPath}) async {
if (Platform.isWindows || Platform.isLinux) {
// Initialize FFI
sqfliteFfiInit();
@@ -45,7 +48,7 @@ class Settings extends ChangeNotifier {
}
final component = Settings._create();
- await component._asyncInit();
+ await component._asyncInit(dbPath);
return component;
}
@@ -76,19 +79,21 @@ class Settings extends ChangeNotifier {
var pPulColor = _getSetting('_pulColor');
var pAllowManualTimeInput = _getSetting('_allowManualTimeInput');
var pDateFormatString = _getSetting('_dateFormatString');
+ var pUseExportCompatability = _getSetting('_useExportCompatability');
// var ...
_graphStepSize = (await pGraphStepSize as int?) ?? TimeStep.day;
_graphStart = DateTime.fromMillisecondsSinceEpoch((await pGraphStart as int?) ?? -1);
_graphEnd = DateTime.fromMillisecondsSinceEpoch((await pGraphEnd as int?) ?? -1);
- _followSystemDarkMode = ((await pFollowSystemDarkMode as int?) ?? 1) == 1 ? true : false;
+ _followSystemDarkMode = ((await pFollowSystemDarkMode as int?) ?? 1) == 1;
_darkMode = ((await pDarkMode as int?) ?? 1) == 1 ? true : false;
_accentColor = createMaterialColor(await pAccentColor as int? ?? 0xFF009688);
_sysColor = createMaterialColor(await pSysColor as int? ?? 0xFF009688);
_diaColor = createMaterialColor(await pDiaColor as int? ?? 0xFF4CAF50);
_pulColor = createMaterialColor(await pPulColor as int? ?? 0xFFF44336);
- _allowManualTimeInput = ((await pAllowManualTimeInput as int?) ?? 1) == 1 ? true : false;
+ _allowManualTimeInput = ((await pAllowManualTimeInput as int?) ?? 1) == 1;
_dateFormatString = (await pDateFormatString as String?) ?? 'yy-MM-dd H:mm';
+ _useExportCompatability = ((await pUseExportCompatability as int?) ?? 0) == 1;
// ...
return;
}
@@ -204,6 +209,14 @@ class Settings extends ChangeNotifier {
_saveSetting('_dateFormatString', newFormatString);
notifyListeners();
}
+ bool get useExportCompatability {
+ return _useExportCompatability;
+ }
+ set useExportCompatability(bool useExportCompatability) {
+ _useExportCompatability = useExportCompatability;
+ _saveSetting('_useExportCompatability', useExportCompatability);
+ notifyListeners();
+ }
}
lib/screens/settings.dart
@@ -91,6 +91,14 @@ class SettingsScreen extends StatelessWidget {
SettingsSection(
title: const Text('data'),
children: [
+ SwitchSettingsTile(
+ initialValue: settings.useExportCompatability,
+ title: const Text('compatability export'),
+ description: const Text('sets export mime type to text instead of csv'),
+ onToggle: (value) {
+ settings.useExportCompatability = value;
+ }
+ ),
SettingsTile(
title: const Text('export'),
leading: const Icon(Icons.save),
@@ -102,7 +110,8 @@ class SettingsScreen extends StatelessWidget {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: $msg')));
}
- }),
+ }
+ , exportAsText: settings.useExportCompatability),
),
SettingsTile(
title: const Text('import'),
test/model/settings_test.dart
@@ -1,4 +1,5 @@
import 'dart:io';
+import 'dart:math';
import 'package:blood_pressure_app/model/settings.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -37,6 +38,7 @@ void main() {
expect(s.pulColor.value, 0xFFF44336);
expect(s.allowManualTimeInput, true);
expect(s.dateFormatString, 'yy-MM-dd H:mm');
+ expect(s.useExportCompatability, false);
});
test('setting fields should notify listeners and change values', () async {
@@ -65,6 +67,7 @@ void main() {
s.pulColor = s.createMaterialColor(0xFF942DA7);
s.allowManualTimeInput = false;
s.dateFormatString = 'yy:dd @ H:mm.ss';
+ s.useExportCompatability = true;
expect(s.graphStart, DateTime.fromMillisecondsSinceEpoch(10000));
@@ -76,6 +79,7 @@ void main() {
expect(s.diaColor.value, 0xFF942DA6);
expect(s.pulColor.value, 0xFF942DA7);
expect(s.allowManualTimeInput, false);
+ expect(s.useExportCompatability, true);
});
test('setting fields should notify listeners and change values', () async {
@@ -98,9 +102,9 @@ void main() {
s.pulColor = s.createMaterialColor(0xFF942DA7);
s.allowManualTimeInput = false;
s.dateFormatString = 'yy:dd @ H:mm.ss';
+ s.useExportCompatability = true;
-
- expect(i, 11);
+ expect(i, 12);
});
});
.gitignore
@@ -42,3 +42,4 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release
+/main.dart.incremental.dill