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?
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
.