Flutter Sembast — The Complete Crash Course
Sembast is a NoSQL persistent store database solution for single process io applications. It’s fully document-based in a single file and is loaded in memory when opened. This can be especially useful when you want to analyze databases that the user selects. In addition, it varies a bit from other solutions, that have their “own” database system and don’t directly open .db
files, it can be very useful to learn. That’s why I will teach you in this article how to use it. Let’s get right into it!
Happy reading!
Note: You can find the whole source code provided in this tutorial here
Installation
The first thing we have to do after creating our app is to add sembast. To do so, we will use the command flutter pub add sembast
. You should be familiar with those commands, otherwise, I recommend you to look up the basics of Flutter again.
Basic Usage
Open Database
Let’s start right away on how to open a database. A database is a single file represented by a path in the file system. That’s why we will first define a string dbPath
and another variable of type DatabaseFactory
. This DatabaseFactory
is now used by a variable of type Database
, where we will pass the dbPath
String. That sounds complicated, but…