Commit c59b045
Changed files (3)
lib
screens
subsettings
lib/model/blood_pressure.dart
@@ -10,10 +10,10 @@ class BloodPressureModel extends ChangeNotifier {
late final Database _database;
BloodPressureModel._create();
- Future<void> _asyncInit(String? dbPath) async {
+ Future<void> _asyncInit(String? dbPath, bool isFullPath) async {
dbPath ??= await getDatabasesPath();
- if (dbPath != inMemoryDatabasePath) {
+ if (dbPath != inMemoryDatabasePath && !isFullPath) {
dbPath = join(dbPath, 'blood_pressure.db');
}
@@ -29,7 +29,7 @@ class BloodPressureModel extends ChangeNotifier {
}
// factory method, to allow for async constructor
- static Future<BloodPressureModel> create({String? dbPath}) async {
+ static Future<BloodPressureModel> create({String? dbPath, bool isFullPath = false}) async {
if (Platform.isWindows || Platform.isLinux) {
// Initialize FFI
sqfliteFfiInit();
@@ -38,7 +38,7 @@ class BloodPressureModel extends ChangeNotifier {
}
final component = BloodPressureModel._create();
- await component._asyncInit(dbPath);
+ await component._asyncInit(dbPath, isFullPath);
return component;
}
lib/model/export_import.dart
@@ -28,7 +28,7 @@ class DataExporter {
}
}
- List<BloodPressureRecord>? parseFile(Uint8List data) {
+ Future<List<BloodPressureRecord>?> parseFile(String filePath, Uint8List data) async {
switch(settings.exportFormat) {
case ExportFormat.csv:
try {
@@ -39,7 +39,7 @@ class DataExporter {
case ExportFormat.pdf:
return null;
case ExportFormat.db:
- throw UnimplementedError('TODO');
+ return loadDBFile(filePath);
}
}
@@ -194,7 +194,11 @@ class DataExporter {
dbPath = join(dbPath, 'blood_pressure.db');
}
return File(dbPath).readAsBytes();
+ }
+ Future<List<BloodPressureRecord>> loadDBFile(String filePath) async {
+ final loadedModel = await BloodPressureModel.create(dbPath: filePath, isFullPath: true);
+ return await loadedModel.all;
}
}
lib/screens/subsettings/export_import_screen.dart
@@ -360,8 +360,11 @@ class ExportImportButtons extends StatelessWidget {
content: Text(AppLocalizations.of(context)!.errCantReadFile)));
return;
}
+ var path = result.files.single.path;
+ assert(path != null); // null state directly linked to binary content
- var fileContents = DataExporter(settings).parseFile(binaryContent);
+ var fileContents = await DataExporter(settings).parseFile(path! ,binaryContent);
+ if (!context.mounted) return;
if (fileContents == null) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(AppLocalizations.of(context)!.errNotImportable)));