Data Persistence in Flutter

Gao
There are many ways to persistence data in flutter. ### Shared Preferences [packages/packages/shared_preferences/shared_preferences at main Β· flutter/packages Β· GitHub](https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences) Shared _preferences is the easy way to persistence data. Wraps platform-specific persistent storage for simple data (NSUserDefaults on iOS and macOS, SharedPreferences on Android, etc.). Data may be persisted to disk asynchronously, and there is no guarantee that writes will be persisted to disk after returning, so this plugin must not be used for storing critical data. ## Database ### Hive [GitHub - hivedb/hive: Lightweight and blazing fast key-value database written in pure Dart.](https://github.com/hivedb/hive) Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by [Bitcask](https://en.wikipedia.org/wiki/Bitcask) . **Before you start** Consider using [Isar](https://github.com/isar/isar) , a Flutter database by the author of Hive that is superior in every way! #### Features * πŸš€ Cross platform: mobile, desktop, browser * ⚑ Great performance (see [benchmark](https://github.com/hivedb/hive#benchmark) ) * ❀️ Simple, powerful, & intuitive API * πŸ”’ Strong encryption built in * 🎈 **NO** native dependencies * πŸ”‹ Batteries included ### Drift [GitHub - simolus3/drift: Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.](https://github.com/simolus3/drift) *Note: Moor has been renamed to drift* Drift is a reactive persistence library for Flutter and Dart, built on top of sqlite. Drift is * **Flexible**: Drift lets you write queries in both SQL and Dart, providing fluent apis for both languages. You can filter and order results or use joins to run queries on multiple tables. You can even use complex sql features like WITH and WINDOW clauses. * πŸ”₯**Feature rich**: Drift has builtin support for transactions, schema migrations, complex filters and expressions, batched updates and joins. We even have a builtin IDE for SQL! * πŸ“¦**Modular**: Thanks to builtin support for daos and imports in sql files, drift helps you keep your database code simple. * πŸ›‘οΈ**Safe**: Drift generates typesafe code based on your tables and queries. If you make a mistake in your queries, drift will find it at compile time and provide helpful and descriptive lints. * ⚑**Fast**: Even though drift lets you write powerful queries, it can keep up with the performance of key-value stores like shared preferences and Hive. Drift is the only major persistence library with builtin threading support, allowing you to run database code across isolates with zero additional effort. * **Reactive**: Turn any sql query into an auto-updating stream! This includes complex queries across many tables * βš™οΈ**Cross-Platform support**: Drift works on Android, iOS, macOS, Windows, Linux and the web. [This template](https://github.com/simolus3/drift/tree/develop/examples/app) is a Flutter todo app that works on all platforms. * πŸ—‘οΈ**Battle tested and production ready**: Drift is stable and well tested with a wide range of unit and integration tests. It powers production Flutter apps. ### Isar [GitHub - isar/isar: Extremely fast, easy to use, and fully async NoSQL database for Flutter](https://github.com/isar/isar) ``` Isar [ee-zahr]: 1 River in Bavaria, Germany. 2 Crazy fast NoSQL database that is a joy to use. ``` #### Features * πŸ’™ **Made for Flutter**. Easy to use, no config, no boilerplate * πŸš€ **Highly scalable** The sky is the limit (pun intended) * 🍭 **Feature rich**. Composite & multi-entry indexes, query modifiers, JSON support etc. * ⏱ **Asynchronous**. Parallel query operations & multi-isolate support by default * πŸ¦„ **Open source**. Everything is open source and free forever! Isar database can do much more (and we are just getting started) * πŸ•΅οΈ **Full-text search**. Make searching fast and fun * πŸ“± **Multiplatform**. iOS, Android, Desktop * πŸ§ͺ **ACID semantics**. Rely on database consistency * πŸ’ƒ **Static typing**. Compile-time checked and autocompleted queries * ✨ **Beautiful documentation**. Readable, easy to understand and ever-improving