Hive is a lightweight local database for Flutter and Dart. It is a fast NoSQL key–value store designed for simple local persistence without SQL, native database engines, or complex setup.
Hive is most commonly used for caching, offline data, user preferences, and small to medium datasets that must persist between app launches.
It is important to note that Hive is currently in maintenance mode. It remains stable and usable, but it is no longer the recommended choice for new projects that require advanced querying or complex data relationships.
Hive stores data in containers called boxes. A box behaves like a persistent map, where data is written to disk and kept in memory after opening.
By default, a standard Box eagerly loads all keys and values into RAM. This makes reads extremely fast but also means memory usage grows linearly with dataset size.
Values can be primitives, collections, or custom Dart objects serialized using TypeAdapters. Data is stored in a compact binary format optimized for speed rather than flexibility.
import 'package:hive_flutter/hive_flutter.dart';
Future<void> initHive() async {
// Initialize Hive
await Hive.initFlutter();
// Open a standard in-memory-backed box
final box = await Hive.openBox<String>('settings');
// Write data
await box.put('theme', 'dark');
// Read data
final theme = box.get('theme');
// Compact the box to reclaim disk space after many updates
await box.compact();
// Close the box when no longer needed
await box.close();
}Boxes are often kept open for the entire app lifecycle to avoid repeated disk access.
A critical limitation of Hive is memory usage. A standard Box loads all data into memory at startup. With large datasets, this leads to slow startup times and excessive RAM consumption.
For large collections, Hive provides LazyBox. A LazyBox keeps only keys in memory and loads values from disk on demand.
LazyBox should be used whenever:
Without LazyBox, Hive does not scale safely beyond relatively small datasets.
Hive is an append-only database. When a value is updated, the new version is appended to the file instead of overwriting the old one. Over time, this causes database files to grow indefinitely, even if the logical dataset remains small.
To mitigate this, Hive provides manual compaction using box.compact(). This rewrites the file and removes obsolete entries.
In production applications, regular compaction is essential. Without it, database files can grow to hundreds of megabytes or more, leading to storage bloat and degraded performance.
SQLite is a relational database with structured queries, joins, and transactions. It is suitable for complex schemas but requires more boilerplate and careful schema management.
Hive trades query power for simplicity and speed. It works best when data access is key-based and predictable.
If the application requires querying, filtering, or relational data, SQLite is usually the safer long-term choice.
Isar is created by the same author as Hive and is widely considered its spiritual successor.
While Hive excels at simple key–value storage, Isar provides:
For new projects that go beyond simple storage or caching, Isar is often preferred over Hive.
Hive remains useful for minimal persistence needs, but Isar is the modern choice for non-trivial local databases in Flutter.
Common issues include:
These mistakes often lead to memory pressure, large database files, or runtime crashes.
Hive becomes problematic when:
In such cases, Isar or a relational database scales more reliably.
12 min • May 16, 2024
When a project grows, sooner or later, a need for sharing logic across multiple clients and a server arises. At LeanCode, we completed a project that extensively employed logic sharing successfully. In this article, we highlight the steps and architecture decisions of the picked solution.
8 min. • Nov 8, 2022
Almost every production-grade app depends on tens of packages. Using them allows for quick implementation of standard functionalities. Take a closer look at 6 useful but not-so-popular Dart and Flutter packages made and tested by LeanCode's devs.
10 min • Oct 27, 2025
In this article, we’re sharing LeanCode’s 12 practical Flutter and Dart patterns that help you write less boilerplate, make your code cleaner, and catch mistakes earlier. Apply these patterns and you'll find yourself coding faster, communicating more clearly with your teammates, and spending less time debugging issues that the compiler could have caught.