showSnackBar method
Future
showSnackBar(
- String message, {
- Color? backgroundColor,
- Color? textColor,
- double? elevation,
- EdgeInsetsGeometry? margin,
- EdgeInsetsGeometry? padding,
- double? width,
- ShapeBorder? shape,
- SnackBarBehavior behavior = SnackBarBehavior.floating,
- SnackBarAction? action,
- Duration duration = const Duration(seconds: 4),
- Animation<
double> ? animation, - VoidCallback? onVisible,
- bool waitDialogToPop = true,
- bool waitPopupRouteToPop = false,
Implementation
Future showSnackBar(
String message, {
Color? backgroundColor,
Color? textColor,
double? elevation,
EdgeInsetsGeometry? margin,
EdgeInsetsGeometry? padding,
double? width,
ShapeBorder? shape,
SnackBarBehavior behavior = SnackBarBehavior.floating,
SnackBarAction? action,
Duration duration = const Duration(seconds: 4),
Animation<double>? animation,
VoidCallback? onVisible,
bool waitDialogToPop = true,
bool waitPopupRouteToPop = false,
}) async {
var observer = snackBarObserver;
var showModalSheet = !waitPopupRouteToPop && observer.isPopupRoute;
var manager = ScaffoldMessenger.maybeOf(this);
var snackBarTheme = Theme.of(this).snackBarTheme;
var navigator = Navigator.of(this);
if (waitDialogToPop) await waitForDialogToClose();
if (waitPopupRouteToPop) await waitForPopupRouteToClose();
var context = navigator.context;
if (showModalSheet && context.mounted) {
var future = showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
isScrollControlled: true,
builder: (ctx) => _Dismiss(
duration: duration,
child: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Card(
color: backgroundColor ?? snackBarTheme.backgroundColor,
shape: shape ?? snackBarTheme.shape,
elevation: elevation,
margin: margin ?? const EdgeInsets.all(15),
child: InkWell(
onTap: () {},
child: Row(
children: [
Expanded(
child: Padding(
padding: padding ?? const EdgeInsets.all(15),
child: Text(
message,
style: snackBarTheme.contentTextStyle
?.copyWith(color: textColor) ??
TextStyle(color: textColor),
textAlign: action == null
? TextAlign.center
: TextAlign.start,
),
),
),
if (action != null)
TextButton(
style: TextButton.styleFrom(
foregroundColor: action.textColor ??
snackBarTheme.actionTextColor),
onPressed: action.onPressed,
child: Text(action.label),
)
],
),
),
),
],
),
),
),
);
if (onVisible != null) onVisible();
await future;
} else {
return manager
?.showSnackBar(SnackBar(
content: Text(
message,
style: TextStyle(color: textColor),
textAlign: action == null ? TextAlign.center : TextAlign.start,
),
backgroundColor: backgroundColor,
elevation: elevation,
margin: margin,
padding: padding,
width: width,
shape: shape,
behavior: behavior,
action: action,
duration: duration,
animation: animation,
onVisible: onVisible,
))
.closed;
}
}