showLocalNotification function

Future<void> showLocalNotification(
  1. NotificationChannel channel,
  2. NotificationMessage message, {
  3. int? notificationId,
})

Displays a local notification using the provided channel and message.

An optional notificationId can be supplied to control update/dismissal; otherwise a unique auto-incrementing id is used. Does nothing on Windows.

Implementation

Future<void> showLocalNotification(
    NotificationChannel channel, NotificationMessage message,
    {int? notificationId}) async {
  if (Platform.isWindows) return;
  AndroidNotificationDetails androidNotificationDetails =
      AndroidNotificationDetails(channel.id, channel.name,
          channelDescription: channel.description,
          importance: Importance.max,
          priority: Priority.high,
          color: channel.color,
          icon: channel.icon != null
              ? '@mipmap/${channel.icon}'
              : '@mipmap/ic_launcher',
          actions: message.actions
              ?.map((e) =>
                  AndroidNotificationAction(e.id, e.title, titleColor: e.color))
              .toList(),
          ticker: channel.ticker);
  NotificationDetails notificationDetails =
      NotificationDetails(android: androidNotificationDetails);
  await flutterLocalNotificationsPlugin.show(
      id: notificationId ?? id++, title: message.title, body: message.body, notificationDetails: notificationDetails,
      payload: message.payload);
}