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.

GLodi
  • 201
  • 1
  • 3
  • 13
  • Does this answer your question? [Sqlite in flutter, how database assets work](https://stackoverflow.com/questions/51384175/sqlite-in-flutter-how-database-assets-work) In this link, the steps to use the SQLite database as an ASSET are fully described. – Esmaeil Ahmadipour Jan 05 '23 at 08:20

2 Answers2

3

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.

Filled Stacks
  • 4,116
  • 1
  • 23
  • 36
1

I've found that this problem is related to:

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

Credits to R. C. Howell

GLodi
  • 201
  • 1
  • 3
  • 13