View SQLite DB in Flutter Application - CodAffection

View SQLite DB in Flutter Application

View SQLite DB in Flutter

In this small article, I’ll show you how you can see the data in SQLite DB of your flutter application. In the previous two articles, we’ve covered the SQLite CRUD Operation in Flutter App.

Credit to Stack Overflow answer here.

Where is Databases are stored?

When you create an SQLite DB programmatically, did you thought about the physical location of the DB? If you are coming from web development, you might look into project explorer for a file with the extension ‘db’. But it’s not in the project directory.

It depends on the environment – android or IOS. To find the location of the database we’ve used a package path_provider in the previous article. The DB will be stored somewhere in the emulator. To see the path, I’ve added the print statement in _initDatabase method of DatabaseHelper class.

_initDatabase() async {
    String dbPath = join(dataDirectory.path, _databaseName);
    print('db location : '+dbPath);

Now to see the printed output, If you are on VS Code, open Debug Console( from the view menu ). In my case, it prints as follows.

View SQLite DB physical location

Connect to the SQLite DB

Now connect to the emulator through adb commands. As per android.developer, It a command-line tool, that lets you communicate with a device/ emulator. 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. Execute following command from the command prompt.

# View all of your emulator
adb devices
# Connect to your selected emulator
adb -s [emulator_name] shell

Now find your package name. It’s there in AndroidManifest.xml[/android/app/src/main/AndroidManifest.xml] file as package attribute.

Now run as the package. from the previous command prompt.

run-as [package_name]
# [package_name] = com.example.sqlite_crud

# Now navigate inside the folder where the db is stored
# which is the location printed from our app
cd [db_path]
# [db_path] - '/data/user/0/com.example.sqlite_crud/app_flutter'

# Connect to the db using sqlite3
sqlite3 [db_file]
# [db_file] : ContactData.db

# Now execute sql queries to view data inside the db.
# select * form contacts;

Hope you find this helpful. End.

Video Tutorial

1 thought on “View SQLite DB in Flutter Application”

  1. Sir, as per your instruction i follow each steps but when i am trying to enter last step ‘sqlite3 crud.db’. After hitting that command it shows an error like ‘sh: sqlite3: inaccessible or not found’. so please give me solution ASAP

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Share via
Copy link