show static method
void
show(
- BuildContext context, {
- required String message,
- Color? backgroundColor,
- Color? textColor,
- IconData? icon,
- Duration? duration,
- SnackBarAction? action,
- SnackBarBehavior? behavior,
- EdgeInsets? margin,
- bool? showCloseButton,
- bool? showProgressIndicator,
- SnackbarPosition? position,
Shows a custom snackbar with full control over appearance. Parameters:
context: BuildContext for showing the snackbarmessage: The text message to displaybackgroundColor: Background color (defaults to grey)textColor: Text color (defaults to white)icon: Optional icon to display before the messageduration: How long the snackbar stays visibleaction: Optional action buttonbehavior: Fixed or floating (defaults to config)margin: Margin around the snackbar (defaults to config)showCloseButton: Whether to show close button (defaults to config)showProgressIndicator: Whether to show countdown progress bar (defaults to config)position: Position of snackbar (top or bottom, defaults to config)
Implementation
static void show(
BuildContext context, {
required String message,
Color? backgroundColor,
Color? textColor,
IconData? icon,
Duration? duration,
SnackBarAction? action,
SnackBarBehavior? behavior,
EdgeInsets? margin,
bool? showCloseButton,
bool? showProgressIndicator,
SnackbarPosition? position,
}) {
// Use provided values or fall back to config defaults
final effectiveDuration = duration ?? SnackbarKitConfig.defaultDuration;
final effectiveBehavior = behavior ?? SnackbarKitConfig.defaultBehavior;
final effectiveMargin = margin ?? SnackbarKitConfig.defaultMargin;
final effectiveShowClose =
showCloseButton ?? SnackbarKitConfig.showCloseButton;
final effectiveShowProgress =
showProgressIndicator ?? SnackbarKitConfig.showProgressIndicator;
final effectivePosition = position ?? SnackbarKitConfig.defaultPosition;
final effectiveBackgroundColor =
backgroundColor ?? SnackbarColors.normalBackground;
final effectiveTextColor = textColor ?? Colors.white;
// If position is TOP, use custom overlay
if (effectivePosition == SnackbarPosition.top) {
_showTopSnackbar(
context,
message: message,
backgroundColor: effectiveBackgroundColor,
textColor: effectiveTextColor,
icon: icon,
duration: effectiveDuration,
action: action,
margin: effectiveMargin,
showCloseButton: effectiveShowClose,
showProgressIndicator: effectiveShowProgress,
);
return;
}
// BOTTOM position - use native SnackBar
if (effectiveShowProgress) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: _SnackbarContentWithProgress(
message: message,
icon: icon,
textColor: effectiveTextColor,
duration: effectiveDuration,
progressColor: effectiveTextColor.withValues(alpha: 0.3),
progressActiveColor: effectiveTextColor,
isTop: false,
),
backgroundColor: effectiveBackgroundColor,
duration: effectiveDuration,
behavior: effectiveBehavior,
margin: effectiveBehavior == SnackBarBehavior.floating
? effectiveMargin
: null,
action: action,
showCloseIcon: effectiveShowClose,
closeIconColor: effectiveTextColor,
padding: EdgeInsets.zero,
),
);
} else {
final content = Row(
children: [
if (icon != null) ...[
Icon(icon, color: effectiveTextColor, size: 24),
const SizedBox(width: 12),
],
Expanded(
child: Text(
message,
style: TextStyle(color: effectiveTextColor, fontSize: 14),
),
),
],
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: content,
backgroundColor: effectiveBackgroundColor,
duration: effectiveDuration,
behavior: effectiveBehavior,
margin: effectiveBehavior == SnackBarBehavior.floating
? effectiveMargin
: null,
action: action,
showCloseIcon: effectiveShowClose,
closeIconColor: effectiveTextColor,
),
);
}
}