-
-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] start sqflite_common_ffi_async based on sqlite_async
- Loading branch information
1 parent
e6286a1
commit 4252869
Showing
3 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
import 'package:sqflite_common_ffi/sqflite_ffi.dart'; | ||
import 'package:sqflite_common_ffi_async/sqflite_ffi_async.dart'; | ||
import 'package:sqflite_example/main.dart'; | ||
|
||
Future<void> main() async { | ||
await mainFfiAsync(); | ||
} | ||
|
||
/// Run using ffi (io or web) | ||
Future<void> mainFfiAsync() async { | ||
await initFfiAsync(); | ||
await runFfiAsync(); | ||
} | ||
|
||
/// Init Ffi for io or web | ||
/// | ||
/// if [noWorker] is true, no isolate is used on io and no web worker is used on the web. | ||
Future<void> initFfiAsync() async { | ||
// getDatabasesPath implementation is lame, use the default one | ||
// but we could also use path_provider | ||
var isSqfliteCompatible = | ||
(Platform.isAndroid || Platform.isIOS || Platform.isMacOS); | ||
//DatabaseFactory? original; | ||
// Save original for iOS & Android | ||
|
||
sqfliteFfiInit(); | ||
databaseFactoryOrNull = databaseFactoryFfiAsync; | ||
|
||
WidgetsFlutterBinding.ensureInitialized(); | ||
// Use sqflite databases path provider (ffi implementation is lame)) | ||
if (isSqfliteCompatible) { | ||
await databaseFactory.setDatabasesPath( | ||
await databaseFactorySqflitePlugin.getDatabasesPath()); | ||
} | ||
} | ||
|
||
/// Run example app. | ||
Future<void> runFfiAsync() async { | ||
mainExampleApp(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters