Setting up Isar Database in Flutter Application
Isar is what Hive aspired to become. A full-featured NoSQL database with support for indexes, complex queries, transactions, and reactive streams. Written in Rust with FFI bindings for Dart, providing performance comparable to SQLite with a significantly more convenient API.
Suitable for projects where Hive hits limitations: you need queries across multiple fields, sorting, database-side filtering, or reactive UI updates when data changes.
Connection and Schema
dependencies:
isar: ^3.1.0+1
isar_flutter_libs: ^3.1.0+1
dev_dependencies:
isar_generator: ^3.1.0+1
build_runner: ^2.4.6
Model with annotations:
@collection
class Product {
Id id = Isar.autoIncrement;
@Index(type: IndexType.value)
late String category;
@Index(composite: [CompositeIndex('price')])
late String name;
late double price;
late bool inStock;
}
Code generation: flutter pub run build_runner build. Creates product.g.dart with collection extensions.
Initialization:
final isar = await Isar.open(
[ProductSchema],
directory: (await getApplicationDocumentsDirectory()).path,
);
Queries — The Main Advantage
This is where Isar far surpasses Hive:
// Filtering + sorting + limit
final products = await isar.products
.filter()
.categoryEqualTo('electronics')
.and()
.inStockEqualTo(true)
.sortByPriceDesc()
.limit(20)
.findAll();
Reactive stream — UI updates when data changes:
Stream<List<Product>> watchProducts() {
return isar.products
.filter()
.inStockEqualTo(true)
.watch(fireImmediately: true);
}
Instead of StreamBuilder with periodic polling, you get a subscription to specific query changes. Clean and efficient.
Transactions. For writing multiple related objects, use writeTxn:
await isar.writeTxn(() async {
await isar.products.putAll(newProducts);
await isar.categories.put(updatedCategory);
});
Without a transaction, each put is a separate write operation. With a transaction, it's atomic.
Limitations to Know
Isar does not support the Web platform (unlike Hive). If your project targets Flutter Web, use Hive or ObjectBox. On Desktop (Windows, macOS, Linux), Isar works via isar_flutter_libs.
Data schema is versioned: when changing a model, specify @collection(accessor: 'products') and configure migration via IsarSchema.migration. Forgotten migration on app update causes database open failure.
Timeline
Isar setup with 3–5 collections, indexes, and basic queries: 1–2 days. With reactive streams, BLoC/Riverpod integration, and migration strategy: 2–4 days. Cost calculated individually after analyzing your data model.







