Mickaël Pascal Vieira Bouix
 · Full Stack Developer

[Custom Action] Recurring Local Notification Push

Hello guys I just figured out doing some research how to schedule a notification push using local notification.




Package Usage: 

Custom action code: 

import 'package:awesome_notifications/awesome_notifications.dart';

Future awesomeNotification(
    int? idMorning,
    String? morningTitle,
    String? morningMessage,
    int? morningHour,
    int? morningMinute,
    bool? morningturnedOn) async {
  AwesomeNotifications().initialize(
    null,
    [
      NotificationChannel(
        channelKey: 'tap_in_notification',
        channelName: 'TapIn Notification',
        channelDescription: 'tap_in',
        importance: NotificationImportance.High,
        channelShowBadge: true,
        locked: false,
      ),
    ],
  );
  AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
    if (!isAllowed) {
      AwesomeNotifications().requestPermissionToSendNotifications();
    }
  });

  String localTimeZone =
      await AwesomeNotifications().getLocalTimeZoneIdentifier();

  if (morningturnedOn == true) {
    await AwesomeNotifications().createNotification(
        content: NotificationContent(
            id: idMorning!,
            channelKey: 'tap_in_notification',
            title: morningTitle,
            body: morningMessage),
        schedule: NotificationCalendar(
            hour: morningHour,
            minute: morningMinute,
            second: 00,
            timeZone: localTimeZone,
            preciseAlarm: true,
            repeats: true));
  }
  if (morningturnedOn == false) {
    await AwesomeNotifications().cancel(idMorning!);
  }
}













Dependency used for IOS: 

 awesome_notifications: ^0.6.21

Dependency used for Android: 

awesome_notifications: ^0.7.4+1 




How to use it:

All the parameters can be found here: 



await AwesomeNotifications().createNotification(
        content: NotificationContent(
            id: idMorning!,
            channelKey: 'tap_in_notification',
            title: morningTitle,
            body: morningMessage),
        schedule: NotificationCalendar(
            hour: morningHour,
            minute: morningMinute,
            second: 00,
            timeZone: localTimeZone,
            preciseAlarm: true,
            repeats: true));
  }


This code means I'll recieve the notification everyday a notification on a time that a setup on the parameters.

Setup those fields


Create an action for the button 







When the user click on the Save button, Will schedule a local push notification every day on the same time you setup on the input text field and the switchvalue will setup if the reminder is active or not.
The  id: idMorning!, we setup on the code can be changed to create more than one notification.

⚠️ I create a now firebase collection to store the notifications, so the user can check their notifications created.


I hope it will help somebody. Any questions dm me, Ill be glad to help. 🤩

8
11 replies