Skip to content

Commit

Permalink
Undo added on swipe to delete alarm using ScaffoldMessenger (#326)
Browse files Browse the repository at this point in the history
* Undo added on swipe to delete alarm using ScaffoldMessenger

* created swipedelte method in contoller and also get.snackbar
  • Loading branch information
Deepanshuigtm authored Jan 15, 2024
1 parent 5c4499e commit 9fd6bbe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
31 changes: 31 additions & 0 deletions lib/app/modules/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,35 @@ class HomeController extends GetxController {
),
);
}

Future<void> swipeToDeleteAlarm(UserModel? user, AlarmModel alarm) async {
AlarmModel? alarm_to_delete;

if (alarm.isSharedAlarmEnabled == true) {
alarm_to_delete = await FirestoreDb.getAlarm(user, alarm.firestoreId!);
await FirestoreDb.deleteAlarm(user, alarm.firestoreId!);
} else {
alarm_to_delete = await IsarDb.getAlarm(alarm.isarId);
await IsarDb.deleteAlarm(alarm.isarId);
}

// Display snackbar
Get.snackbar(
'Alarm deleted',
'The alarm has been deleted.',
duration: const Duration(seconds: 4),
snackPosition: SnackPosition.BOTTOM,
mainButton: TextButton(
onPressed: () async {
if (alarm.isSharedAlarmEnabled == true) {
await FirestoreDb.addAlarm(user, alarm_to_delete!);
} else {
await IsarDb.addAlarm(alarm_to_delete!);
}
},
child: const Text('Undo'),
),
);
}
}

10 changes: 1 addition & 9 deletions lib/app/modules/home/views/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,7 @@ class HomeView extends GetView<HomeController> {
// Main card
return Dismissible(
onDismissed: (direction) async {
if (alarm.isSharedAlarmEnabled ==
true) {
await FirestoreDb.deleteAlarm(
controller.userModel.value,
alarm.firestoreId!);
} else {
await IsarDb.deleteAlarm(
alarm.isarId);
}
await controller.swipeToDeleteAlarm(controller.userModel.value,alarm);
},
key: ValueKey(alarms[index]),
child: Obx(
Expand Down

0 comments on commit 9fd6bbe

Please sign in to comment.