@@ -1286,7 +1286,35 @@ class AddOrUpdateAlarmController extends GetxController {
1286
1286
}
1287
1287
1288
1288
Future <void > createProfile () async {
1289
- profileModel = ProfileModel (
1289
+ try {
1290
+ if (profileTextEditingController.text.trim ().isEmpty) {
1291
+ Get .snackbar (
1292
+ 'Error' ,
1293
+ 'Profile name cannot be empty' ,
1294
+ snackPosition: SnackPosition .BOTTOM ,
1295
+ backgroundColor: Colors .red,
1296
+ colorText: Colors .white,
1297
+ duration: const Duration (seconds: 3 ),
1298
+ margin: const EdgeInsets .all (10 ),
1299
+ );
1300
+ return ;
1301
+ }
1302
+
1303
+ bool exists = await IsarDb .profileExists (profileTextEditingController.text.trim ());
1304
+ if (exists) {
1305
+ Get .snackbar (
1306
+ 'Error' ,
1307
+ 'A profile with this name already exists' ,
1308
+ snackPosition: SnackPosition .BOTTOM ,
1309
+ backgroundColor: Colors .red,
1310
+ colorText: Colors .white,
1311
+ duration: const Duration (seconds: 3 ),
1312
+ margin: const EdgeInsets .all (10 ),
1313
+ );
1314
+ return ;
1315
+ }
1316
+
1317
+ profileModel = ProfileModel (
1290
1318
profileName: profileTextEditingController.text,
1291
1319
deleteAfterGoesOff: deleteAfterGoesOff.value,
1292
1320
snoozeDuration: snoozeDuration.value,
@@ -1342,20 +1370,43 @@ class AddOrUpdateAlarmController extends GetxController {
1342
1370
guardian: guardian.value,
1343
1371
isCall: isCall.value,
1344
1372
ringOn: isFutureDate.value,
1345
- );
1373
+ );
1374
+
1375
+ if (homeController.isProfileUpdate.value) {
1376
+ var profileId =
1377
+ await IsarDb .profileId (homeController.selectedProfile.value);
1378
+ print (profileId);
1379
+ if (profileId != 'null' ) profileModel.isarId = profileId;
1380
+ print (profileModel.isarId);
1381
+ await IsarDb .updateAlarmProfiles (profileTextEditingController.text);
1382
+ }
1346
1383
1347
- if (homeController.isProfileUpdate.value) {
1348
- var profileId =
1349
- await IsarDb .profileId (homeController.selectedProfile.value);
1350
- print (profileId);
1351
- if (profileId != 'null' ) profileModel.isarId = profileId;
1352
- print (profileModel.isarId);
1353
- await IsarDb .updateAlarmProfiles (profileTextEditingController.text);
1384
+ await IsarDb .addProfile (profileModel);
1385
+ homeController.selectedProfile.value = profileModel.profileName;
1386
+ storage.writeProfile (profileModel.profileName);
1387
+ homeController.writeProfileName (profileModel.profileName);
1388
+
1389
+ Get .snackbar (
1390
+ 'Success' ,
1391
+ 'Profile created successfully' ,
1392
+ snackPosition: SnackPosition .BOTTOM ,
1393
+ backgroundColor: Colors .green,
1394
+ colorText: Colors .white,
1395
+ duration: const Duration (seconds: 2 ),
1396
+ margin: const EdgeInsets .all (10 ),
1397
+ );
1398
+ } catch (e) {
1399
+ debugPrint ('Error creating profile: $e ' );
1400
+ Get .snackbar (
1401
+ 'Error' ,
1402
+ 'Failed to create profile. Please try again.' ,
1403
+ snackPosition: SnackPosition .BOTTOM ,
1404
+ backgroundColor: Colors .red,
1405
+ colorText: Colors .white,
1406
+ duration: const Duration (seconds: 3 ),
1407
+ margin: const EdgeInsets .all (10 ),
1408
+ );
1354
1409
}
1355
- await IsarDb .addProfile (profileModel);
1356
- homeController.selectedProfile.value = profileModel.profileName;
1357
- storage.writeProfile (profileModel.profileName);
1358
- homeController.writeProfileName (profileModel.profileName);
1359
1410
}
1360
1411
}
1361
1412
0 commit comments