How to set every day to repeat the alarm in alarm manager for flutter?

175 Views Asked by At

I want to create a everyday alarm which repeat periodically without any break. I try to use android_alarm_manager for this task. Using this, I could create a periodic alarm by setting for a week after that alarm not working anymore.i need alarm daily not 7 days only

static Future scheduleRepeatable(Alarm alarm) async {

for (int weekday = 0; weekday < 7; ++weekday) {
  if (alarm.weekday[weekday]) {
    final callbackId = alarm.callbackIdOf(weekday);
    final time = alarm.timeOfDay.toComingDateTimeAt(weekday);

    await _oneShot(callbackId, time);
  
  }
}

}

1

There are 1 best solutions below

1
Aia Ashraf On
>     static Future scheduleRepeatable(Alarm alarm) async {   final alarmManager = await getSystemService(AlarmManager);   final interval
> = alarm.repeatInterval.inMilliseconds;
> 
>   for (int weekday = 0; weekday < 7; ++weekday) {
>     if (alarm.weekday[weekday]) {
>       final triggerTime = alarm.timeOfDay.toComingDateTimeAt(weekday);
>       await alarmManager.setInexactRepeating(
>         RTC_WAKEUP,
>         triggerTime.millisecondsSinceEpoch,
>         interval,
>         alarm.callbackIdOf(weekday),
>       );
>     }   } }