showNotification function

SonnerNotification showNotification({
  1. NotificationData? data,
  2. NotificationPriority priority = NotificationPriority.high,
  3. Alignment alignment = Alignment.bottomCenter,
  4. required Widget builder(
    1. BuildContext,
    2. NotificationData,
    3. SonnerNotification
    ),
})

Show a notification and return a controllable instance

This function tries to use the global context. Make sure NotificationProvider is in the widget tree.

Implementation

SonnerNotification showNotification({
  NotificationData? data,
  NotificationPriority priority = NotificationPriority.high,
  Alignment alignment = Alignment.bottomCenter,
  required Widget Function(BuildContext, NotificationData, SonnerNotification) builder,
}) {
  // Get the current context from the provider
  final context = NotificationProvider.currentContext;
  if (context == null) {
    throw StateError('NotificationProvider not found. Make sure to wrap your app with NotificationProvider.');
  }

  return NotificationProvider.of(context).showNotification(
    data: data,
    priority: priority,
    alignment: alignment,
    builder: builder,
  );
}