notify method

Future<void> notify({
  1. required String title,
  2. required String body,
  3. NotificationPriority priority = NotificationPriority.normal,
  4. List<NotificationAction> actions = const [],
  5. Duration? autoHide,
  6. String? category,
})

Show a notification.

Implementation

Future<void> notify({
  required String title,
  required String body,
  NotificationPriority priority = NotificationPriority.normal,
  List<NotificationAction> actions = const [],
  Duration? autoHide,
  String? category,
}) async {
  final notification = NeomageNotification(
    id: 'notif_${DateTime.now().millisecondsSinceEpoch}',
    title: title,
    body: body,
    priority: priority,
    actions: actions,
    autoHide: autoHide ?? const Duration(seconds: 5),
    category: category,
  );

  _history.add(notification);
  if (_history.length > _maxHistory) {
    _history.removeAt(0);
  }

  for (final backend in _backends) {
    if (await backend.isSupported()) {
      await backend.show(notification);
      _events.add(NotificationShownEvent(notification.id));
    }
  }
}