Bersabeh
Bersabeh

Reputation: 1

How to allow users to swipe away an alarm notification to stop the alarm in flutter?

I am working on a flutter alarm app where I want users to be able to swipe away the alarm notification to stop the alarm. Currently, I have implemented an onStop function that stops the alarm when the user presses a button, but I want this to work when the user swipes the notification away.

I am using the alarm package along with flutter_local_notifications to trigger alarms and notifications. However, I am unsure how to detect when the notification is dismissed (swiped away) and use that event to stop the alarm.

Main alarm logic:

void stopAlarm(BuildContext context, AlarmModel alarm) async {
  alarmManager.stopAlarm(alarm);
}

Alarm card UI:

ElevatedButton(
  onPressed: onStop,
  style: ElevatedButton.styleFrom(
    backgroundColor: Colors.red,
  ),
  child: const Text('Stop'),
),

Upvotes: 0

Views: 21

Answers (0)

Related Questions