banner static method
void
banner({})
Implementation
static void banner({
required String message,
String? title,
UToastType type = UToastType.neutral,
IconData? icon,
List<Widget>? actions,
String? actionLabel,
VoidCallback? onAction,
bool showDismiss = true,
String? dismissLabel,
Color? backgroundColor,
Color? foregroundColor,
bool clearQueue = true,
}) {
if (message.isNullOrEmpty()) return;
final BuildContext ctx = navigatorKey.currentContext!;
final Color background = backgroundColor ?? (type == UToastType.neutral ? _scheme.surfaceContainerHighest : _backgroundFor(type));
final Color foreground = foregroundColor ?? (type == UToastType.neutral ? _scheme.onSurface : _foregroundFor(type));
final IconData? resolvedIcon = icon ?? _iconFor(type);
final ScaffoldMessengerState messenger = ScaffoldMessenger.of(ctx);
if (clearQueue) messenger.clearMaterialBanners();
// Ensure the banner always has at least one action (MaterialBanner requires it)
final List<Widget> resolvedActions = actions ??
<Widget>[
if (actionLabel != null)
TextButton(
onPressed: () {
dismissBanner();
onAction?.call();
},
style: TextButton.styleFrom(foregroundColor: foreground),
child: Text(actionLabel),
),
if (showDismiss || actionLabel == null)
TextButton(
onPressed: dismissBanner,
style: TextButton.styleFrom(foregroundColor: foreground),
child: Text(dismissLabel ?? U.s.close),
),
];
messenger.showMaterialBanner(
MaterialBanner(
backgroundColor: background,
leading: resolvedIcon != null ? Icon(resolvedIcon, color: foreground) : null,
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (title != null) UTextTitleSmall(title, color: foreground),
UTextBodyMedium(message, color: foreground),
],
),
actions: resolvedActions,
),
);
}