show static method
void
show(})
Shows a customizable toast notification.
context - The build context.
message - The text message to display.
duration - How long the toast should be visible. Defaults to 2 seconds.
backgroundColor - Custom background color.
textColor - Custom text color.
icon - Optional icon to display.
metadata - Optional metadata logger.
Implementation
static void show(
BuildContext context,
String message, {
Duration duration = const Duration(seconds: 2),
Color? backgroundColor,
Color? textColor,
IconData? icon,
Map<String, dynamic>? metadata,
}) {
// Log the toast
_logger.logToast(message, metadata: metadata);
// Remove existing toast
_currentToast?.remove();
final overlay = Overlay.of(context);
_currentToast = OverlayEntry(
builder: (context) => _ToastWidget(
message: message,
backgroundColor: backgroundColor,
textColor: textColor,
icon: icon,
),
);
overlay.insert(_currentToast!);
Future.delayed(duration, () {
_currentToast?.remove();
_currentToast = null;
});
}