showNotification<T> function

OverlaySupportEntry showNotification<T>({
  1. String? title,
  2. Widget? titleWidget,
  3. Widget? body,
  4. bool isSwipeDismissable = true,
  5. Duration? duration,
  6. bool? showDismissLink,
  7. Widget? leading,
  8. OverlaySupportBuilder? trailing,
  9. OverlaySupportCallback? onTap,
})

Implementation

OverlaySupportEntry showNotification<T>(
    {String? title,
    Widget? titleWidget,
    Widget? body,
    bool isSwipeDismissable = true,
    Duration? duration,
    bool? showDismissLink,
    Widget? leading,
    OverlaySupportBuilder? trailing,
    OverlaySupportCallback? onTap}) {
  OverlaySupportEntry? entry;
  entry = showOverlayNotification(
    (context) {
      final overlay = context.themes.platformOverlayTheme;

      final child = Material(
        elevation: overlay.elevation,
        child: ListTileTheme(
          style: ListTileStyle.list,
          textColor: overlay.foregroundColor,
          iconColor: overlay.foregroundColor,
          dense: false,
          child: Container(
              color: overlay.backgroundColor,
              child: SafeArea(
                bottom: false,
                child: ListTile(
                    title: titleWidget ?? Text(title ?? "Notification"),
                    onTap: () {
                      onTap?.call(context, entry);
                    },
                    contentPadding: overlay.padding,
                    subtitle: body,
                    leading: leading,
                    trailing: trailing?.call(context, () => entry) ??
                        (showDismissLink == true
                            ? SunnyNotificationDismissLink(entry: () => entry!)
                            : null)),
              )),
        ),
      );
      return isSwipeDismissable
          ? Dismissible(
              direction: DismissDirection.up,
              onDismissed: (_) {
                entry?.dismiss(animate: false);
              },
              child: child,
              key: Key("overlay-${i++}"),
            )
          : child;
    },
    duration: duration ?? 0.seconds,
  );
  return entry;
}