Simple SQFlite database example in Flutter

Simple SQFlite database example in FlutterSuragchBlockedUnblockFollowFollowingJan 7There are a number of tutorials out there about how to setup a SQLite database in Flutter using the SQFlite plugin.

They were helpful but I found myself getting lost in the details.

My purpose in this post is to give you a minimal example that you can get through in 10 minutes.

Once you have it working, you can go on to some of the more advanced topics in other tutorials.

Here is the minimal app that we will be making:Pressing each button will perform the related operation on the database using SQFlite.

For this minimal example, you will do the following steps:Add the dependenciesMake a database helper classMake your app layout with the button logicDependenciesOpen the pubspec.

yaml file and add the following lines to the dependencies section:sqflite: ^0.


0+1path_provider: ^0.


1Change the version number to whatever is the most current for sqflite and path_provider.

Database helperCreate a new file in the lib folder and call it database_helper.


Copy in the following code:App codeOpen your main.

dart file and replace it with the following code:FinishedThat’s it!.You should be able to run the app now.

Pressed the buttons an watch the logged output from the print statements.

(In Android Studio make sure you have the Run tab selected.

)Read back through the code comments to understand what the different parts do.

If there is anything that you don’t understand, you can ask in a comment below.

Further readingSQFlite documentationUsing sqflite in your Flutter applicaiton effectivelyFlutter SQLite example — CRUD operations with sqflite pluginSQFlite Database in flutter.

. More details

Leave a Reply