Skip to content

Commit 4fa6e02

Browse files
committed
Fix windows build
1 parent df9ed1e commit 4fa6e02

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

lib/services/database.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
// Dart imports:
2+
import 'dart:io';
3+
14
// Package imports:
5+
import 'package:path/path.dart';
6+
import 'package:path_provider/path_provider.dart';
27
import 'package:sqflite/sqflite.dart';
38

49
// Project imports:
@@ -74,8 +79,17 @@ class MyLibraryDb {
7479
}
7580

7681
Future<Database> _initDatabase() async {
77-
final databasePath = await getDatabasesPath();
78-
final path = '$databasePath/mylibrary.db';
82+
String databasePath;
83+
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
84+
final directory = await getApplicationSupportDirectory();
85+
databasePath = directory.path;
86+
try {
87+
await Directory(databasePath).create(recursive: true);
88+
} catch (_) {}
89+
} else {
90+
databasePath = await getDatabasesPath();
91+
}
92+
final path = join(databasePath, 'mylibrary.db');
7993

8094
return await openDatabase(
8195
path,

0 commit comments

Comments
 (0)