thebigbrownBox
thebigbrownBox

Reputation: 51

How to repeat a notification in flutter with date

So I started learning flutter a month ago and I want to put what I have learnt into practice by building app. However, I don't know to approach this project.

Below is the summary of the app:

I live in a town where an event(market day) occurs every 3 days. For example, if today is a market day, the next market day would be 3 days from today. I don't have any problem with the UI, my main issue is the functionality.

The Functionality:

The app should display an upcoming(or present) market day, and users can tick a checkbox if they want to be notified.

All suggestions are welcome. Thanks in advance.

Upvotes: 1

Views: 808

Answers (1)

Piotr
Piotr

Reputation: 667

  class NotificationService {
  ....
  Future<void> scheduleNotifications() async {
    await flutterLocalNotificationsPlugin.zonedSchedule(
        0,
        "Notification Title",
        "This is the Notification Body!",
        tz.TZDateTime.now(tz.local).add(const Duration(minutes: 5)),
        platformChannelSpecifics,
        androidAllowWhileIdle: true,
        uiLocalNotificationDateInterpretation:
            UILocalNotificationDateInterpretation.absoluteTime);
  }
}

Local notification scheduler using dates. Now as far as the logic is concerned you will need to use some mathematical equasion to predict all upcoming market days upfront and schedule notifications programatically rather than comparing current date with previous market day etc as this kind of logic depends on app being opened and used regularly.

More info about creating and scheduling local notifications can be found here.

Hope this helps!

Upvotes: 2

Related Questions