Commit 633279e
Changed files (2)
lib/model/blood_pressure.dart
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:convert';
-import 'dart:io';
import 'package:blood_pressure_app/screens/error_reporting.dart';
import 'package:collection/collection.dart';
@@ -66,11 +65,6 @@ class BloodPressureModel extends ChangeNotifier {
/// [dbPath] is the path to the folder the database is in. When [dbPath] is left empty the default database file is
/// used. The [isFullPath] option tells the constructor not to add the default filename at the end of [dbPath].
static Future<BloodPressureModel> create({String? dbPath, bool isFullPath = false}) async {
- if (Platform.isWindows || Platform.isLinux) { // TODO: drop desktop support
- sqfliteFfiInit();
- databaseFactory = databaseFactoryFfi;
- }
-
final component = BloodPressureModel._create();
await component._asyncInit(dbPath, isFullPath);
return component;
lib/model/export_import.dart
@@ -168,6 +168,7 @@ class ExportFileCreator {
}
pw.Widget _buildPdfTitle(DateFormat dateFormatter, BloodPressureAnalyser analyzer) {
+ if (analyzer.firstDay == null || analyzer.lastDay == null) return pw.Text(localizations.errNoData);
return pw.Container(
child: pw.Text(
localizations.pdfDocumentTitle(dateFormatter.format(analyzer.firstDay!), dateFormatter.format(analyzer.lastDay!)),
@@ -281,39 +282,23 @@ class Exporter {
var fileContents = await ExportFileCreator(settings, exportSettings, csvExportSettings, pdfExportSettings,
localizations, theme, exportColumnsConfig).createFile(data);
String filename = 'blood_press_${DateTime.now().toIso8601String()}';
- String ext;
- switch(exportSettings.exportFormat) {
- case ExportFormat.csv:
- ext = 'csv';
- break;
- case ExportFormat.pdf:
- ext = 'pdf';
- break;
- case ExportFormat.db:
- ext = 'db';
- break;
- }
+ String ext = exportSettings.exportFormat.name;
String path = await FileSaver.instance.saveFile(name: filename, ext: ext, bytes: fileContents);
- if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
- messenger.showSnackBar(SnackBar(content: Text(localizations.success(path))));
- } else if (Platform.isAndroid || Platform.isIOS) {
- if (exportSettings.defaultExportDir.isNotEmpty) {
- JSaver.instance.save(
- fromPath: path,
- androidPathOptions: AndroidPathOptions(toDefaultDirectory: true)
- );
- messenger.showSnackBar(SnackBar(content: Text(localizations.success(exportSettings.defaultExportDir))));
- } else {
- Share.shareXFiles([
- XFile(
- path,
- mimeType: MimeType.csv.type
- )
- ]);
- }
+ assert(Platform.isAndroid || Platform.isIOS);
+ if (exportSettings.defaultExportDir.isNotEmpty) {
+ JSaver.instance.save(
+ fromPath: path,
+ androidPathOptions: AndroidPathOptions(toDefaultDirectory: true)
+ );
+ messenger.showSnackBar(SnackBar(content: Text(localizations.success(exportSettings.defaultExportDir))));
} else {
- messenger.showSnackBar(const SnackBar(content: Text('UNSUPPORTED PLATFORM')));
+ Share.shareXFiles([
+ XFile(
+ path,
+ mimeType: MimeType.csv.type
+ )
+ ]);
}
}