top of page

[Flutter/dart] Set regular monthly notifications with local_notification


Overview


A library called flutter_local_notification makes it easy to create regular notifications. However, this library only provides daily and weekly recurring notifications, and there is no method for creating monthly recurring notifications.

So, here's how to send a notification on a fixed day every month.



Method


It's not a very cool solution, but it's pretty good at "creating a one-time notification for months". For example, if you want to send a notification on the 1st of every month, create a notification for January 1st, February 1st, and March 1st, and if the app starts after January 1, create a notification for April 1st, and so on. (You can't create an April 1st notification if the app isn't opened once in three months, but that's not a concern as the app is no longer in use.)


for (int i=0; i<3; i++) {
    
    int _id=i;
    DateTime _date= DateTime(2021, i+1, 1, 19, 0);
    
    await flutterLocalNotificationsPlugin.schedule(
      _id, 'title', 'content', _date, platformChannelSpecifics);
}
//Methods to craete instances of flutterLocalNotificationsPlugin, platformChannelSpecifics is omitted.

As a caveat, if you do not separate the id, only the last notification will come (one notification with one id), so separate the ids.

Also, the processing will be quite heavy, so create a notification with another isolate. In that case, use flutter_isolate (local_notification is a process that uses platform_channel, so the compute method cannot be used). Click here for how to use flutter_isolate.


there are minor problems such as if you cross the year, you have to change the generation of _date, and if it is the 30th of every month, what to do in February, but as a rough guideline, it is like this. Then apply according to your own application.



Lastly


I think there is a certain demand for sending notifications on a fixed day every month. For example, check the results of this month, or reminder to buy a monthly paper released on the 23rd of every month. If possible, I want the official to respond.

Recent Posts

See All

[Flutter/Dart] Format string with TextField

What want to do I want to create an input form using TextField. For example, if the input content is a monetary amount, I would like to display it in 3-digit delimiters with a ¥ prefix. Rather than ha

Comentarios


Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page