Start a Project

Isar database in Flutter

Choosing the right database in a fast-paced environment like Flutter is crucial. That’s where Isar Database comes in. Isar is a NoSQL solution specifically built for Flutter development. This step-by-step guide walks you to implemented Isar Database in Flutter Isar’s smooth integration, Type-Safe models, and Cross-Platform compatibility, providing you with a comprehensive toolkit for effective data management.

Key Features of Isar Database

You can visit our Flutter app development page for more flutter-related information.

Implementation

1. Setup :

Create new project and add the following dependency into your project

2. Initialize Database :

Firstly, create customer model class and define the properties for the customer (name, email and id) as follows :

Annotate customer class with @collection, define id field (id = Isar.autoIncrement) and Execute the following command to start the build_runner:

3. Open Isar database

Create a method to open Isar database and call this method from initState as shown below :

dir :- Get the directory information where we need to initialize the isar instance.

Isar.open() :- method to open the database and return instance it takes arguments as List of schemas (UserModelSchema in our example code) and directory path.

caching in flutter

4. Add new User in database

Create a method saveUser() to add new user in database as shown below :

saveUser() :- Method takes instance of new user to save in database.

put() :- put method add new user to the database.

5. Retrieve all the users

For Retrieving all the user from database create method as follows and read the users using findAll method :

Complete code

Output of complete code

Conclusion

Thanks for reading this article ❤️

I hope this blog will help you to learn about how to implement Isar Database in Flutter and you will be able to implement it. For more updates, make sure to keep following Mobikul Blogs to learn more about mobile app development.

Happy Learning ✍️

Other Blogs you may like..

Hive database in flutter

Sqflite database in flutter

Reference

https://pub.dev/packages/isar

Exit mobile version