import 'package:isar/isar.dart'; import 'package:kulinar_app/models/recipe_class.dart'; /// Handles user data persistence related app storage class IsarHandler { late Future db; IsarHandler() { db = _openDB(); } /// Stores the given `data` as a string with the `key`. Future save(Recipe recipe) async { final isar = await db; return await isar.writeTxn(() => isar.recipes.put(recipe)); } /// Fetches all recipes Future> load() async { final isar = await db; return await isar.recipes.where().findAll(); } /// Fetches the Recipe related to the given `title`. Future fetch(String title) async { final isar = await db; return await isar.recipes.filter().titleEqualTo(title).findFirst(); } Future _openDB() async { if (Isar.instanceNames.isEmpty) { return await Isar.open( [RecipeSchema], inspector: true, ); } return Future.value(Isar.getInstance()); } }