Reputation: 201
I have a SQLite .db file that I want to access through sqflite on Flutter. Where in the Flutter project am I supposed to put it so that I can access it both on Android and iOS? How do I make sure that it's shipped with the apk? All examples that I found assume that the db needs to be created from scratch at the first launch.
Upvotes: 7
Views: 13054
Reputation: 201
I've found that this problem is related to:
https://stackoverflow.com/a/51387985/3902715
Credits to R. C. Howell
Upvotes: 1
Reputation: 4346
You can put the db file in your assets folder and declare it in your pubspec.yaml. On startup you can write it out to disk and then use that path with your connection string to connect the db.
You can read from assets using
var dbContent =
await rootBundle.load('assets/database/mydb.db');
Then write it out to your file system and go from there.
Upvotes: 5