7

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.

1

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1

I've found that this problem is related to:

https://stackoverflow.com/a/51387985/3902715

Credits to R. C. Howell

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.