# Using Isar Database with Flutter Local Data Management with GetX

- Link: https://www.rultech.com/flutter-local-data-management/
- Published: 2025-05-02T17:52:36+05:30
- Author: Nikita Patgiri

In today’s app development world, speed and efficiency are everything—especially
when it comes to **Flutter local data management**. Whether you’re building offline-
first features or simply need a fast and reliable database, **Isar** is one of the
best choices available for Flutter developers. It’s designed for high performance
and minimal overhead, making it ideal for local storage tasks.

When paired with **GetX**, managing local data in Flutter becomes even more powerful.
GetX handles state management, dependency injection, and reactivity with very little
boilerplate, streamlining your workflow. Together, Isar and GetX offer a clean and
efficient solution for **Flutter local data management**, ensuring smooth data flow
between your UI and backend logic.

This combo is perfect for developers looking to implement offline-first capabilities,
optimize performance, and maintain scalable architecture. Whether you’re a beginner
exploring best practices or a seasoned pro refining your stack, understanding how
to manage data locally in Flutter using Isar and GetX is a valuable skill.

In this guide, we’ll walk you through setting up Isar, integrating it with GetX,
and implementing common use cases for **Flutter local data management**. By the 
end, you’ll be equipped to build responsive, offline-capable apps with confidence.

In this post, we’ll walk through using **Isar Database with Flutter GetX**, covering:

 * 🛠️ Setting up Isar
 * 💾 Creating Models
 * ⚙️ Building GetX Controller
 * 🧪 Displaying Data in the UI
 * 🔁 Performing CRUD operations

##### Step 1: Add Dependencies

Add these to your `pubspec.yaml`:

    ```language-dart
    dependencies:
      flutter:
        sdk: flutter
      get: ^4.6.6
      isar: ^3.1.0
      isar_flutter_libs: any
      path_provider: ^2.1.1
    ```

Also include build tools for code generation:

    ```language-dart
    dev_dependencies:
      build_runner: ^2.3.3
      isar_generator: ^3.1.0
    ```

##### Step 2: Create Your Model

Let’s create a simple `Note` model.

    ```language-dart
    import 'package:isar/isar.dart';

    part 'note.g.dart';

    @collection
    class Note {
      Id id = Isar.autoIncrement; // Auto-increment ID
      late String title;
      late String content;
      late DateTime createdAt;
    }
    ```

Then run this to generate the code:

    ```language-dart
    flutter pub run build_runner build
    ```

##### Step 3: Create a GetX Controller

    ```language-dart
    import 'package:get/get.dart';
    import 'package:isar/isar.dart';
    import 'package:path_provider/path_provider.dart';
    import '../models/note.dart';

    class NoteController extends GetxController {
      late Isar isar;
      RxList<Note> notes = <Note>[].obs;

      @override
      void onInit() {
        super.onInit();
        _initIsar();
      }

      Future<void> _initIsar() async {
        final dir = await getApplicationDocumentsDirectory();
        isar = await Isar.open([NoteSchema], directory: dir.path);
        loadNotes();
      }

      Future<void> loadNotes() async {
        notes.value = await isar.notes.where().findAll();
      }

      Future<void> addNote(String title, String content) async {
        final note = Note()
          ..title = title
          ..content = content
          ..createdAt = DateTime.now();

        await isar.writeTxn(() => isar.notes.put(note));
        loadNotes();
      }

      Future<void> deleteNote(int id) async {
        await isar.writeTxn(() => isar.notes.delete(id));
        loadNotes();
      }
    }
    ```

##### Step 4: Build the UI with GetX

    ```language-dart
    import 'package:flutter/material.dart';
    import 'package:get/get.dart';
    import 'controllers/note_controller.dart';

    class NotePage extends StatelessWidget {
      final NoteController controller = Get.put(NoteController());

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: Text('Isar Notes')),
          body: Obx(() => ListView.builder(
                itemCount: controller.notes.length,
                itemBuilder: (_, index) {
                  final note = controller.notes[index];
                  return ListTile(
                    title: Text(note.title),
                    subtitle: Text(note.content),
                    trailing: IconButton(
                      icon: Icon(Icons.delete),
                      onPressed: () => controller.deleteNote(note.id),
                    ),
                  );
                },
              )),
          floatingActionButton: FloatingActionButton(
            onPressed: () {
              controller.addNote("Note ${DateTime.now()}", "Generated content");
            },
            child: Icon(Icons.add),
          ),
        );
      }
    }
    ```

#####  Final Thoughts

Isar + GetX gives you:

 * 💡 Easy state management
 * 💾 Powerful and fast local storage
 * ⚡ Automatic UI refreshes on data changes

It’s the perfect pair for building offline-first and high-performance Flutter apps.
