Sign in
Create production ready Flutter app with Isar database.
Struggling with local data in Flutter? This guide explores Isar, a fast NoSQL database. Learn to implement CRUD operations, complex queries, full-text search, and multi-entry indexes with practical code examples for high-performance, reactive apps.
Getting stuck managing local data in your Flutter app? You’re not alone. Many Flutter developers look for a fast, reactive, developer-friendly database that supports complex queries, full text search, and JSON without boilerplate.
This article focuses on Isar, the coolest Flutter database built for high performance and compile-time safety. We'll explore features like multi-entry indexes, Isar collections, basic CRUD operations, and query modifiers, and then execute queries using them.
Isar is a fast, NoSQL database for Flutter with native Dart APIs . It runs directly inside your app with no external dependencies. The database is optimized for mobile devices and supports both Android and iOS.
Stores objects with a schema defined using Dart classes.
Supports reactive data queries with minimal boilerplate.
Works offline, with a free forever license.
Explanation:
Your Flutter app opens a database instance and interacts with Isar collections. Queries are handled via a builder pattern, and query modifiers return reactive results.
Before working with the Isar app, you must install and initialize it properly. You define schemas, enable query generation, and use build\_runner
to generate code.
Run the following command to generate schemas:
1flutter pub run build_runner build
This will scan your models and output the final .g.dart
files used in the database instance.
“Isar brings speed and simplicity to data management. Now, it's time to put that power into your creation.”
Collections in Isar are defined using Dart classes . You annotate each class with @Collection()
and mark the ID and indexed fields.
1() 2class User { 3 Id id = Isar.autoIncrement; 4 5 String name; 6 7 (caseSensitive: false) 8 String email; 9 10 int age; 11 12 User({required this.name, required this.email, required this.age}); 13}
Explanation:
This defines a User class, creating an ISAR collection. The email field is indexed and case-insensitive, and the ID is automatically generated.
To access the ISAR database, open an instance pointing to your final dir
path.
1final dir = await getApplicationDocumentsDirectory(); 2final isar = await Isar.open( 3 [UserSchema], 4 directory: dir.path, 5);
Explanation:
You must await the Isar because the operation is asynchronous. UserSchema
is generated during codegen. The directory points to where your database file is stored.
Performing basic CRUD operations is simple and type-safe.
1await isar.writeTxn(() async { 2 await isar.users.put(User(name: 'John', email: 'john@email.com', age: 30)); 3});
Explanation:
Wrap your changes inside writeTxn. The put function saves or updates the object. It’s fast, reactive, and works offline.
To delete, use:
1await isar.writeTxn(() async { 2 await isar.users.delete(1); 3});
Isar supports a powerful query language with query modifiers. You can filter by values, chain conditions, or sort results.
1final results = await isar.users 2 .filter() 3 .ageGreaterThan(25) 4 .and() 5 .emailContains('example', caseSensitive: false) 6 .findAll();
Explanation:
This query fetches users over 25 with emails that contain “example.” The filters are compile-time checked and eliminate typos.
Isar has JSON support, allowing you to import/export objects.
1final userJson = user.toJson(); 2final userFromJson = User.fromJson(userJson);
To edit properties, load the object, change values, and update inside a transaction.
1await isar.writeTxn(() async { 2 final user = await isar.users.get(1); 3 if (user != null) { 4 user.name = "Updated Name"; 5 await isar.users.put(user); 6 } 7}); 8```​ 9 10## Full Text Search in Isar 11 12Use `(type: IndexType.value)` to support full text search. 13 14```dart 15(type: IndexType.value, caseSensitive: false) 16late String bio;
Search by:
1final matches = await isar.users 2 .filter() 3 .bioWordsElementEqualTo('flutter') 4 .findAll();
Explanation:
Indexes split text into words. You can perform token-based full-text queries efficiently.
Isar lets you index multiple values in a list field.
1(type: IndexType.hashElements) 2late List<String> tags;
Now you can query entries containing specific tags:
1final tagged = await isar.users 2 .filter() 3 .tagsElementEqualTo('developer') 4 .findAll();
Explanation:
With hash elements, you create multi-entry indexes. You can find objects based on individual list elements.
Enable inspector by running your app in debug mode with this flag:
1flutter run --dart-define=ISAR_INSPECTOR=true
Visit the inspector link shown in your debug console. It lets you explore collections, data, indexes, and even perform complex queries visually.
Explore the standout features of Isar, a high-performance NoSQL database for Flutter.
Feature | Description |
---|---|
CRUD | Type-safe create, read, update, delete |
Full Text Search | Token-based indexed search |
Multi Entry Indexes | Query list fields |
JSON Support | Export/import model data |
Write Transaction | Async, safe updates |
Inspector | Visual DB exploration in debug mode |
If you're building a Flutter app and need a fast, reactive database that integrates with Dart deeply, Isar is a smart choice. With features like compile-time safety, multi-entry indexes, and JSON support, managing your data becomes smooth and predictable. From basic CRUD operations to complex queries, Isar does it with clean syntax and zero boilerplate.