How to set one or more days to repeat the alarm weekly in alarm manager for flutter?

714

Well, you can repeat that process for every day the user selects. Keep the _id you assign for each of the 7 days, so you can cancel specific days when the user disables them.

By the way, DateTime has a weekday property that indicates what day of the week it represents. So to find the next Monday for example, you can add a day to DateTime.now() until its weekday == 1.

Share:
714
Rangana Udara
Author by

Rangana Udara

Updated on December 23, 2022

Comments

  • Rangana Udara
    Rangana Udara over 1 year

    I want to create a weekly alarm which repeat periodically in given days. I try to use android_alarm_manager for this task. Using this, I could create a periodic alarm by giving a specific date to start and a duration of 7 days.

    void _createPeriodicAlarm() async {
        final _id = Random().nextInt(pow(2, 31));
        await AndroidAlarmManager.periodic(const Duration(days: 7), _id, _printHello, startAt: DateTime(2020, 8, 1)); }
    

    But what I want is, let user to pick one or more days to repeat the alarm weekly. How can I do this using android_alarm_manager or any other such method?

    • KKKKK
      KKKKK over 3 years
      try AlarmClock instead
    • Rangana Udara
      Rangana Udara over 3 years
      @KKKKK Is it this library?
    • KKKKK
      KKKKK over 3 years
    • KKKKK
      KKKKK over 3 years
      Alarm Clock is usually used to set the clock time application in your device from your apk
    • KKKKK
      KKKKK over 3 years
      I saw now the flutter tag, idk if alarmClock is available with flutter
    • Rangana Udara
      Rangana Udara over 3 years
      @KKKKK There is a library called AlarmClock for flutter, but there is no proper documentation or a example. Anyway thank you. 😃