Best Local Database for Flutter Apps: A Complete Guide

Dinko MarinacDinko Marinac
8 min read

Introduction

When building Flutter applications with any type of offline support, choosing the right local database is crucial for performance and maintainability.

As far as persistence goes, the official docs recommend 3 choices:

For most of us, a combination of a local database for data and shared preferences for user settings is what’s needed.

Local databases in Flutter had their ups and downs, most notably the situation with Hive and Isar, which have been wildly popular, but left abandoned by the author and are now maintained by the community.

The default choice nowadays seems to be anything built on top SQLite (like Drift), but there is more to the choice than meets the eye. Sometimes NoSQL database is more than enough and sometimes the right choice is not to have a local database at all.

In this article, I’ll explore the top local databases, their key features, the level of support for different platforms, maintenance, and most importantly - when to choose it.

When Not to Use a Local Database

Before diving into database options, consider if you actually need one. For simple data storage needs, consider these alternatives an alternative like SharedPreferences or just an in-memory storage.

When should you not use a database? Generally, when:

  • Your data structure is simple

  • You're storing a low amount of data (< 1MB)

  • You don't need complex queries

  • You don't require data relationships

  • You don’t care about data structure changes

One of the most popular solutions seems to be serialization to a String and saving the data in shared_preferences. If you need encryption, you can use flutter_secure_storage.

With that out of the way, let’s dive into the database choices.

Hive

Hive is a lightweight and blazing-fast key-value database written in pure Dart and strongly encrypted using AES-256.

In Hive, data is stored in boxes. Boxes are comparable to collections in NoSQL databases. They don’t have a structure and can contain anything. However, most of the time, we do want structure and that’s where adapters come in. They can be generated with hive_generator or written manually. Using the generator handles migrations as well, while writing adapters manually means you have to handle them yourselves.

The biggest selling point for Hive is its performance and simplicity. The bad side of the deal is that Hive is not maintained any longer, but the community stepped in and created a successor: hive_ce. All the necessary packages like generator and flutter specific versions also have a CE counterpart.

Because Hive is written purely in Dart, it supports all the platforms, including Web.

Isar

Isar was supposed to be supercharged Hive to address its weaknesses but ended up in the same place as Hive. Labeled as an “Extremely fast, easy to use, and fully async NoSQL database for Flutter.”, its main advantage over Hive was supposed to be queries, multi-isolate support, and links between objects.

Isar is a phenomenal library with its ACID support, schema changes, full-text search, isolate support, and more. It is different from Hive and is based on collections and transactions. You can read more about it here. Unlike Hive, Isar doesn’t really support web, but it does all other platforms.

The main drawback here is the same as Hive → maintainability.

The author just left the project abandoned. To make things worse, the core of the library is written in Rust, which makes it really inconvenient for most Flutter devs to fork it. Once again, people are relying on a community fork.

SQLite (sqflite)

Package sqflite allows Flutter interaction with a SQLite database.

While super basic, it does everything you expect it to: transactions, batches, helpers for queries, support for background execution on Android and iOS.

Out-of-the-box support comes for Android, iOS and MacOS. Futher support for Desktop and DartVM is available trough qflite_common_ffi package, and there also an experimental web support with sqflite_common_ffi_web.

Main drawback is you have to write raw SQL, which is something most people don’t like and therefore, use packages like Drift or Floor which have abstractions over SQLite and ORM-like querying.

Drift (formerly Moor)

Drift is a reactive persistence library for Flutter and Dart, built on top of SQLite. It has emerged as the go-to choice for type-safe SQL database access. It's actively maintained by Simon Binder and has excellent documentation and community support.

Drift offers robust migration support, type safety, and supports all platforms ( including web). It's particularly well-suited for enterprise applications where type safety and SQL compliance are crucial.

It’s so popular that there is actually Postgres support, Sentry integration, Powersync integration for automatic data sync, database viewer, and much more.

If you are stuck and don’t know what to choose, my go-to recommendation would be Drift.

Floor

Floor provides a simpler SQLite abstraction compared to Drift but with less active maintenance. It’s inspired by the Room database for Android and the moment you see the code, you see the similarity. There is no web support.

ObjectBox

ObjectBox is a German company that devoted itself to building the best local database for offline support in mobile. This out of the gate means that it’s not suitable for the web.

ObjectBox is designed for offline first apps. The NoSQL API and background sync enable a lot of use cases like IoT, automotive, or POS devices. The performance is phenomenal compared to any other database on this list, but it comes at a cost: it’s not open-source. There are plans to open source the core in version 4.1 according to the blog.

ObjectBox Performance Graph Flutter

Taken from: https://github.com/objectbox/objectbox-dart/tree/main/objectbox#flutter-database-performance-benchmarks

In addition, it’s the first on-device Vector Search for mobile, IoT, and other embedded devices. It’s highly performant and empowers you to do on-device RAG or on-device generative AI applications.

If your app needs to be offline first, is used in bad connectivity environments and you need generative AI on-device, this is highly recommended.

Couchbase Lite

Couchbase Lite fits the same category as ObjectBox. It’s an embedded JSON-document database with vector search and peer-to-peer sync for mobile and IoT apps. It’s maintained by Couchbase as a part of their offer.

While it’s a NoSQL database, it uses SQL++ for data queries, which enables all the SQL developers to effectively continue to use their knowledge. It also comes with a type-safe builder API.

Realm

Realm is a mobile database designed to replace SQLite and ORMs. It was wildly popular, especially after MongoDB acquired it. The acquisition lead to Realm becoming the first choice for mobile apps using MongoDB on the backend due to automatic data syncing.

Realms API shares a lot in common with how queries, indexes, and transactions work on Mongo.

The bad news here is, Realm SDKs and Atlas Device Sync deprecation was announced in September 2024. There are community branches for the SDK without the sync feature, but because this is a super important feature for the users of Realm, migration is required. Powersync already has a working version and a migration guide, while ObjectBox has an alpha version.

Sembast

Sembast labels itself as “Yet another NoSQL persistent store database solution for single process io applications”. Supports DartVM and Flutter.

Web support is available by using sembast_web package and it can also work on top of SQLite by using sembast_sqflite package.

It's particularly well-suited for medium-sized applications that need flexibility without the complexity of SQL. The database supports encryption, compound queries, and automatic data type handling, though it may not match the raw performance of Isar or ObjectBox for large datasets.

Making the Choice

With all these options, it’s hard to make a choice. To make it simpler for you, I’ve made a flow chart that should help you make the decision.

There are some considerations that are not built into the chart:

  • Drift is a default choice and the right one for most projects due to extensive documentation and capabilities

  • Hive Community edition is the simplest solution, perfect for prototyping and simple requirements, and offers web support

  • Isar is a worse version of Hive, in my opinion, due to Rust core and the author’s radio silence, not recommended for new projects

  • Realm doesn’t feature sync with Mongo anymore, so continue using it only if you like the API, maintainability-wise, there are better options, not recommended for new projects

  • ObjectBox and Couchbase Lite are commercial products, so if you don’t want to pay, don’t use them

  • Shared Preferences and Flutter Secure Storage are more than enough if you only want to save super simple things or store them temporarily

The last thing I want to mention is offline-first apps. ObjectBox and Couchbase come with sync built-in. For everybody else, you can use Powersync or build your own solution. Powersync can be used with Drift.

Conclusion

When choosing a local database for your Flutter application, consider your specific needs rather than following trends. With its robust documentation and SQL capabilities, Drift is a reliable choice for most projects.

If you need something simpler, Hive Community Edition offers a straightforward solution with web support. For enterprise-level offline-first applications, ObjectBox and Couchbase Lite provide built-in sync capabilities, though they come with commercial licensing. Alternatively, you can implement offline synchronization with solutions like Powersync, which integrates well with Drift.

Remember that sometimes the simplest solution, Shared Preferences or Flutter Secure Storage, might be all you need.

If you found this useful, like and follow me for more content like this. To learn when new articles are published, follow me on Twitter and LinkedIn.

16
Subscribe to my newsletter

Read articles from Dinko Marinac directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Dinko Marinac
Dinko Marinac

Mobile app developer and consultant. CEO @ MOBILAPP Solutions. Passionate about the Dart & Flutter ecosystem.