SQLite in Flutter

Greg Perry
17 min readJul 7, 2019

Demonstrating the Dart package, dbutils.

This article introduces the Dart package, dbutils. It was written to work with the SQLite plugin, sqflite, which was written by Alex Tekartik. The plugin knows how to ‘talk to’ an SQLite database, while the Dart package knows how to ‘talk to’ the plugin. The end result allows you to manipulate the SQLite database that much easier. Before continuing, I would suggest installing the Dart package now as it includes the very same example app demonstrated here in this article. Follow the three steps below, and you’re on your way using an SQLite database in your Flutter app.

dbutils on pub.dev

I Like Screenshots. Click For Gists.

As always, I prefer using screenshots over gists to show concepts rather than just show code in my articles. I find them easier to work with frankly. However, you can click or tap on these screenshots to see the code they represent in a gist or in Github. Ironically, it’s better to read this article about mobile development on your computer than on your phone. Besides, we program on our computers — not on our phones. For now.

Let’s begin.

Other Stories by Greg Perry

What’s on the Table?

In the example app, we have the class, Employee, which extends the class library called, DBInterface. It itself is found in the library file, Employee.dart, and implements the three required properties: Two getters called name and version and one function called onCreate(). The ‘name’ is the name of the database to contain all the tables you would then define in the function, onCreate(). The ‘version’ of course is the version number of the database. Pretty straightforward so far.

Employee.dart *

So, in the screenshot above, you see what makes up the Dart file, Employee.dart. Looking inside the onCreate() function, you’ll realize it’s required you be comfortable with SQL as it’s used to create and manipulate the data tables. Listed at the end of the Employee class, are functions used to save…

Greg Perry