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 usingsqflite_common_ffi
You 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.
2
Answers
something I usually did is this way, hope this snap shot help you
then from the main I call my init to create db like this
I hope this helps you to could initialize your db