Janos Kiss
·Available for hire – DM me to build your next app

Local notification, scheduled repeatedly or not

Updated version in the comments


Disclaimer: I am not a coder and I have no idea what i am doing, just experimenting, so I am not sure this is the best way to do this, but tested on iPhone and worked.

So keep in mind this is just a quick experiment not a full featured code, but you can easily customise it.

Read the documentation of the package, it is possible to add, emoji, image, sound for the notification.
Pub dev package:
https://pub.dev/packages/awesome_notifications

Add
to the home page as an On Page Load action.

CUSTOM ACTION
No return
parameters:
required: id: integer

and it can be almost anything that you want to change in the code: time: integer, boolean to turn on/off, image path, string for the messages etc. 

Require Pub Dev Dependency:

awesome_notifications: ^0.6.21

Code Snippet that will notify on every minute

import 'package:awesome_notifications/awesome_notifications.dart';

Future awesomeNotification(int id) async {
  AwesomeNotifications().initialize(
      // set the icon to null if you want to use the default app icon
      'resource://drawable/res_app_icon',
      [
        NotificationChannel(
            channelGroupKey: 'scheduled_channel_group',
            channelKey: 'scheduled',
            channelName: 'Scheduled notifications',
            channelDescription: 'Notification channel for scheduled tests',
            defaultColor: Color(0xFF9D50DD),
            ledColor: Colors.white)
      ],
      // Channel groups are only visual and are not required
      channelGroups: [
        NotificationChannelGroup(
            channelGroupkey: 'scheduled_channel_group',
            channelGroupName: 'Scheduled group')
      ],
      debug: true);

  AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
    if (!isAllowed) {
      // This is just a basic example. For real apps, you must show some
      // friendly dialog box before call the request method.
      // This is very important to not harm the user experience
      AwesomeNotifications().requestPermissionToSendNotifications();
    }
  });
  
String localTimeZone = await AwesomeNotifications().getLocalTimeZoneIdentifier();
  await AwesomeNotifications().createNotification(
      content: NotificationContent(
        id: 10,
        channelKey: 'scheduled',
        title: 'Morning Reminder \u{1F4A9}',
        body: 'Simple body',
        bigPicture:
            'https://tecnoblog.net/wp-content/uploads/2019/09/emoji.jpg',
        notificationLayout: NotificationLayout.BigPicture,
      ),
      schedule: NotificationCalendar(
          second: 0,
          timeZone: localTimeZone,
          preciseAlarm: true,
          repeats: true));
}

You can modify the schedule section with the following attributes:
https://pub.dev/packages/awesome_notifications#notificationcalendar-schedule-in-push-data---optional

So
if you want to schedule a recurring notification on every day at a specific time, you should modify the schedule section on the code snippets, something like this:
This will notify every day at 9:15 am

 schedule: NotificationCalendar(
          hour: 9,
          minute: 15,
          second: 0,
          timeZone: localTimeZone,
          preciseAlarm: true,
          repeats: true)


i just needed this simple recurring notification but if you modify it please let us know what you did.

4
32 replies