Help wanted:How to use the options parameter in the in the openDatabase() method. #892
-
Hello, thanks very much for this excellent package if any of the creators are reading this. I'm very new to programming and dart as a whole and I'm trying to open a database using the databaseFactoryFfiObj.openDatabase() method and I'm getting some errors when I pass an onCreate argument saying that there is no parameter named onCreate. When I checked, what I was getting was that I was supposed to use the options parameter rather, so I tried to use that but I didn't know how to use the onCreate in that parameter. If anybody could help me resolve this I would be very grateful, thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
sqflite assumes a decent knowledge of flutter and SQLite in general and I know the doc is not very good. Maybe starting with SQLite is not the easiest (shared preferences could be easier so start with if you just need to save a few data). There are some example of opening/versioning here: https://github.com/tekartik/sqflite/blob/master/sqflite/doc/opening_db.md#migration The API is slightly different when you use the factory (basically all the parameters are in the options).
We could help you better if you show what you are doing (some code) and the exact error (from the console) you are getting as we cannot guess what you are doing wrong nor what error you are seeing. One important note: if you use onCreate, you have to specify a version too. |
Beta Was this translation helpful? Give feedback.
-
Ok I see, indeed the var db = await dbFactoryFfiObj.openDatabase(path,
options: OpenDatabaseOptions(
version: 1,
onCreate: (db, version) async {
// ... your onCreate implementation here
})); |
Beta Was this translation helpful? Give feedback.
Ok I see, indeed the
DatabaseFactory.openDatabase
API is slightly different then the sqflite openDatabase API that you might have seen in some example. All the parameters must be set in an options object. You should do something like: