show method
void
show({
- required String message,
- Duration duration = const Duration(seconds: 3),
- SnackbarType type = SnackbarType.info,
- String? actionLabel,
- VoidCallback? onAction,
- EdgeInsets padding = const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
- double elevation = 6,
- Color? backgroundColor,
- TextStyle? textStyle,
- SnackBarBehavior behavior = SnackBarBehavior.floating,
- ShapeBorder? shape,
- Alignment alignment = Alignment.bottomCenter,
Implementation
void show({
required String message,
Duration duration = const Duration(seconds: 3),
SnackbarType type = SnackbarType.info,
String? actionLabel,
VoidCallback? onAction,
EdgeInsets padding = const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
double elevation = 6,
Color? backgroundColor,
TextStyle? textStyle,
SnackBarBehavior behavior = SnackBarBehavior.floating,
ShapeBorder? shape,
Alignment alignment = Alignment.bottomCenter,
}) {
final color = backgroundColor ?? _getColor(type);
final style = textStyle ?? const TextStyle(color: Colors.white);
final snackBar = SnackBar(
content: Text(message, style: style),
duration: duration,
behavior: behavior,
elevation: elevation,
shape: shape ??
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
backgroundColor: color,
action: actionLabel != null
? SnackBarAction(
label: actionLabel,
textColor: Colors.white,
onPressed: onAction ?? () {},
)
: null,
margin: const EdgeInsets.all(12),
);
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}