I followed the following tutorial on the official site for sqflite: https://pub.dev/packages/sqflite
But on this line
var databasesPath = await getDatabasesPath();
I get the following error:
Exception has occurred. StateError (Bad state: databaseFactory not initialized databaseFactory is only initialized when using sqflite. When using
sqflite_common_ffiYou must calldatabaseFactory = databaseFactoryFfi;before using global openDatabase API )
These are my dependencies:
dependecies:
flutter:
sdk: flutter
sqflite: ^2.2.8
path: ^1.8.2
I tried to open the Database without getting a path from getDatabasePath():
await openDatabase('demo.db', version: 1,...
But this throws the same error on openDatabase.
As I am not using sqflite_common_ffi I do not know what to do and would appreciate your help.
Edit: I now also tried to use the complete example on the end of the page docs.flutter.dev/cookbook/persistence/sqlite. I think it is some kind of configuration error, because the same project works on another machine of mine.
dependencies:
sqflite_common_ffi: any
//in main.dart write this:
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
Future main() async {
// Initialize FFI
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
runApp(MyApp());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With