Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - where to put own SQLite .db file?

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.

like image 352
GLodi Avatar asked Mar 14 '19 16:03

GLodi


People also ask

Where should I put SQLite database?

The SQLite DLL file can be placed on Windows in C:WINDOWSsystem32 folder if needed to manage your database files.

How do you store data in SQLite database in Flutter?

sqflite | Flutter Package Inside the onCreate property, we can build our database table using execute method. To insert the data or model inside the database we use the insert method. It takes a table name and JSON value. To fetch the data from the database we use the query method.

How do I show SQLite database in Flutter?

Connect to the SQLite DB this tool will be there inside the platform-tools folder in your android SDK path. SDK path will be shown in android studio > sdk manager. Now navigate inside the sdk location and then inside the platform-tools folder. where you could see adb.exe.


2 Answers

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.

like image 114
Filled Stacks Avatar answered Oct 17 '22 01:10

Filled Stacks


I've found that this problem is related to:

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

Credits to R. C. Howell

like image 25
GLodi Avatar answered Oct 17 '22 01:10

GLodi