showSnackbar static method
dynamic
showSnackbar(
- String message, {
- bool top = false,
- Color? backgroundColor,
- TextStyle? style,
- double? elevation,
- EdgeInsetsGeometry? margin,
- EdgeInsetsGeometry? padding,
- double? width,
- ShapeBorder? shape,
- HitTestBehavior? hitTestBehavior,
- SnackBarBehavior? behavior,
- SnackBarAction? action,
- double? actionOverflowThreshold,
- bool? showCloseIcon,
- Color? closeIconColor,
- Duration duration = _snackBarDisplayDuration,
- Animation<
double> ? animation, - void onVisible()?,
- Widget? leading,
- DismissDirection? dismissDirection,
- Clip clipBehavior = Clip.hardEdge,
muestra mensaje recibe message, backgroundColor Recibe el color que se mostrara
style Puede ser nulo y pode defecto toma un valor
top Permite eligir si mostrara el mensaje en la parte superior o inferior por defecto es false
Implementation
static showSnackbar(
String message, {
bool top = false,
Color? backgroundColor,
TextStyle? style,
double? elevation,
EdgeInsetsGeometry? margin,
EdgeInsetsGeometry? padding,
double? width,
ShapeBorder? shape,
HitTestBehavior? hitTestBehavior,
SnackBarBehavior? behavior,
SnackBarAction? action,
double? actionOverflowThreshold,
bool? showCloseIcon,
Color? closeIconColor,
Duration duration = _snackBarDisplayDuration,
Animation<double>? animation,
void Function()? onVisible,
Widget? leading,
DismissDirection? dismissDirection,
Clip clipBehavior = Clip.hardEdge,
}) async {
top
? messagerKey.currentState!.clearMaterialBanners()
: messagerKey.currentState!.clearSnackBars();
final snackbar = Text(
message,
style: style ?? const TextStyle(color: Colors.white, fontSize: 15),
);
/// Mostrara el mensaje en la parte superior
if (top) {
messagerKey.currentState!.showMaterialBanner(MaterialBanner(
animation: animation,
contentTextStyle: style,
leading: leading,
elevation: elevation,
margin: margin,
onVisible: onVisible,
padding: padding,
backgroundColor: backgroundColor ?? const Color(0xFF323232),
content: snackbar,
actions: const [
SizedBox(),
]));
await Future.delayed(const Duration(milliseconds: 3000))
.then((value) => messagerKey.currentState!.clearMaterialBanners());
} else {
messagerKey.currentState!.showSnackBar(SnackBar(
content: snackbar,
backgroundColor: backgroundColor,
action: action,
actionOverflowThreshold: actionOverflowThreshold,
animation: animation,
behavior: behavior ?? SnackBarBehavior.floating,
clipBehavior: clipBehavior,
closeIconColor: backgroundColor,
dismissDirection: dismissDirection ?? DismissDirection.down,
duration: duration,
elevation: elevation,
hitTestBehavior: hitTestBehavior,
margin: margin,
onVisible: onVisible,
padding: padding,
shape: shape ?? _validShape(behavior),
showCloseIcon: showCloseIcon,
width: width,
));
}
}