showNotification static method

Future<void> showNotification({
  1. required int id,
  2. required String title,
  3. required String body,
  4. String? payload,
})

Implementation

static Future<void> showNotification({
  required int id,
  required String title,
  required String body,
  String? payload,
}) async {
  List<String> lines = AppRunTime.listLogNotifier.value.entries
      .toList()
      .filter((e) => !e.value.isRead)
      .map((e) => "${e.value.request?.method}: ${e.value.request?.path}")
      .toList();

  AndroidNotificationDetails androidDetails = AndroidNotificationDetails(
    channelId,
    channelName,
    channelDescription: channelDescription,
    importance: Importance.max,
    priority: Priority.high,
    groupKey: groupKey,
    setAsGroupSummary: lines.length > 1,
    styleInformation: lines.length > 1
        ? InboxStyleInformation(
            lines,
            contentTitle: 'You have ${lines.length} new items',
            summaryText: 'Tap to view all items',
          )
        : null,
  );

  final iosDetails = DarwinNotificationDetails(
    presentBanner: false,
    presentBadge: false,
    presentList: true,
    threadIdentifier: groupKey,
  );

  NotificationDetails details = NotificationDetails(
    android: androidDetails,
    iOS: iosDetails,
  );

  await _notificationsPlugin.show(
    id,
    title,
    body,
    details,
    payload: payload,
  );
}