'Is it possible to get a GUI for an SQLite database created in flutter for android simulator?

I created a database main.db in flutter, located at the ApplicationDocumentsDirectory.path. This worked without any problem.

But for easier maintanance and not always having to create an SQL-Statement to see the data or structure I'd like to get a GUI to watch the database. First I wanted to use Browser DB for SQLite but I don't know where the database is saved on my notebook, if so. Also I can't find it with Agent Ransack either.

Is there a way to find the database or maybe an easier way to see the database on a GUI?
I use Visual Studio Code for development if that's any help.



Solution 1:[1]

There is one beautiful package for db viewer if you are using moor_db

https://pub.dev/packages/moor_db_viewer

Very easy to integrate and very easy to view the tables

Solution 2:[2]

In addition to F-1 answer if you need a more sophisticated tool for manage your database there is the SQLite Studio. You could do the follow steps to achieve this:

  1. To get database (with adb):

    adb -s emulator-5554 pull /data/data/com.your.package.yourappname/databases/you_database_name.db .

  2. If you need change it and update (It will override android db)

    adb -s emulator-5554 push ~/Desktop/you_database_name.db /data/data/com.your.package.yourappname/databases/

  3. Here is the link to SQLite Studio (works in macOS, linux and windows) https://sqlitestudio.pl/

Solution 3:[3]

Since this is a top google result for browsing a sqlite db in a simulator for flutter devs, for others who stumble upon this, here's a solution for iOS simulators as well:

You need to find your db file first, which for iOS sit under /Users/<youruser>/Library/Developer/CoreSimulator/Devices/. Assuming you know the db name, you could get the full path like this:

find /Users/<youruser>/Library/Developer/CoreSimulator/Devices/ -name "<name>.db"

For example, using sqflite's getDatabasesPath() as the location to create the database, I can see the file sits at /Users/<youruser>/Library/Developer/CoreSimulator/Devices//<devid>/data/Containers/Data/Application/<appid>/Documents/<name>.db

And if you were testing on more than one simulator, you can look up the device id with:

xcrun simctl list # look under "== Devices ==" or grep for "Booted" if it's running

Then browse the db using a tool like DB Browser for SQLite as suggested earlier if sqlite3 is cumbersome. If using vscode, you could give SQLTools with its SQLite driver a try.

Solution 4:[4]

In my case, I was facing problems with Android Studio so created this executable script.

adb exec-out run-as your-package-name cat databases/your_db_name.db > your_db_name.db
sqlite3 your_db_name.db "PRAGMA wal_checkpoint"
start "DB Browser For SQLite.exe" your_db_name.db

Of course, you could also have another program in place of DB Browser to open the DB file.

To answer your original question of "where the database is saved", it is saved in the "data/data/your_package/databases" but if you're on Android 10+, the package folder might not be visible to file manager apps without a "special root mode" ( reddit thread ) because of Scoped Storage.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prajeet Naga
Solution 2 Cassio Seffrin
Solution 3 qix
Solution 4