
Flutter databases – sqflite, hive, ObjectBox, and Moor
Flutter is one of the most popular cross-platform mobile frameworks used by developers worldwide according to Statista, 2021. While the study also determined that the majority of mobile developers still used native tools, Flutter is becoming a serious developer platform, and with its growth there is a growing need for Flutter databases.
A quick note on Flutter and Dart: Flutter is an open-source UI software development kit created by Google. Dart is the programming language in which developers code Flutter apps. Dart is an object-oriented programming language.
Flutter databases / Flutter Dart data persistence
While the database market is huge and dynamic, there are only few options to choose from if you are a Flutter / Dart app developer. Before we dive into the Flutter database options, advantages and disadvantages, we’re taking a very quick look at databases to make sure, we share a common ground.
What is a database?
A database is a piece of software that allows the storage and systematic use of digital information, in other words: data persistence. As opposed to mere caching, data is reliably stored and available to work with unless actively deleted. A database typically allows developers to store, access, search, update, query, and otherwise manipulate data in the database via a developer language or API. These types of operations are done within an application, in the background, typically hidden from end users. Many applications need a database as part of their technology stack. The most typical database operations are CRUD: Create, Read, Update, Delete.
What are the major types of databases?
There are many types of databases. For our purpose, the most important differentiations are non-relational (NoSQL) versus relational databases (SQL), cloud databases versus edge databases, and maybe embedded versus in-memory. However, databases can be further distinguished by additional criteria e.g. the data types they support, or the way they scale – and definitions can vary.
What is an ORM?
An Object relational Mapper (ORM) is not a database. We’re bringing this up mainly, because we see it confused often. It is a layer that sits on top of a database and makes it easier to use. This is typically especially relevant when the database is a relational database (SQL) and the programming language used is object-oriented. As noted above, Dart is an object-oriuented programming language.
The Flutter Dart data persistence landscape
At this point in time, the database landscape for Flutter Dart is still very limited. So, let us quickly introduce the current market players. Note: We are adding in Moor, because with that few player it is just one more option available and therefore, at this moment in time, should be part of the Flutter Dart data persistence landscapes, in our minds.
- Firebase Realtime DB is a cloud-hosted database. It stores data as JSON and synchronizes it to connected clients.
- Hive is a lightweight key-value database written in Dart for Flutter applications, inspired by Bitcask.
- ObjectBox DB is a highly performant lightweight NoSQL database with an integrated Data Sync. It stores objects.
- sqflite is a wrapper around SQLite, which is a relational database without direct support for Dart objects.
- Moor is a reactive persistence library for Flutter and Dart, built ontop of sqlite.
What is the best Flutter Dart database?
This of course depends… Make up your own mind with the following comparison matrix as a starting point. Note: With very few options to choose from, the following overview is sometimes a bit comparing apples🍎 and pears🍐.
Data persistence | Description | Primary Model | Location of data | Language | License | Fun Fact |
Firebase Realtime Database | Mobile Backend as a Service (MBaaS) | NoSQL | Google Cloud | Dart | Proprietary | acquired by Google in 2014 |
hive | Light key-value DB for Flutter | NoSQL | local | Dart | Apache 2.0 | Munich brew |
ObjectBox | High-performance Flutter DB | NoSQL | local, self-hosted server / cloud | Dart | Bindings are Apache 2.0 | Munich-brew out-of-the-box data sync solution |
sqflite | SQLite plugin for Flutter | relational | local | SQL | SQLite is public domain, sqflite lib is MIT | good old SQLite |
Moor | ORM for SQLite | used on top of a relational DB | local | Dart | SQLite is public domain, Moor lib is MIT | Room spelled backwards |