Code updated on December 15, 2022
There 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 you 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 dependencies
- Make a database helper class
- Make your app layout with the button logic
Start by creating a new Flutter project called
Open the pubspec.yaml file and add the following lines to the dependencies section:
You can find the current versions for these packages here:
Create a new file in the
lib folder and call it database_helper.dart.
Copy in the following code:
Open your main.dart file and replace it with the following code: