From f560759fe6d1790dfa3f63fa73b6aeeff1b50a97 Mon Sep 17 00:00:00 2001 From: Aditya Chauhan Date: Tue, 4 Mar 2025 01:01:09 +0530 Subject: [PATCH] Refactor updateAlarmProfiles to use currentProfile and add validation --- lib/app/data/providers/isar_provider.dart | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/app/data/providers/isar_provider.dart b/lib/app/data/providers/isar_provider.dart index 249dbf06..ef7ecd7f 100644 --- a/lib/app/data/providers/isar_provider.dart +++ b/lib/app/data/providers/isar_provider.dart @@ -378,21 +378,28 @@ class IsarDb { return profileSet; } + // Do some changes in the updateAlarmProfiles function to update the profile name in the alarms table static Future updateAlarmProfiles(String newName) async { final isarProvider = IsarDb(); final db = await isarProvider.db; final currentProfileName = await storage.readProfile(); + final currentProfile = await IsarDb.getProfile(currentProfileName); + if (currentProfile == null) { + + print("Got Error: Current profile '$currentProfileName' not found."); + return; + } List alarmsModels = await db.alarmModels .where() .filter() - .profileEqualTo(currentProfileName) + .profileEqualTo(currentProfileName) .findAll(); for (final item in alarmsModels) { item.profile = newName; - updateAlarm(item); + await updateAlarm(item); } - } +} static Future deleteAlarm(int id) async { final isarProvider = IsarDb();