showToast method
void
showToast({
- required String text,
- Duration? duration,
- SnackBarAction? action,
- TextStyle? textStyle,
- Color? backgroundColor,
- SnackBarBehavior? behavior,
- bool hideCurrentSnackbar = true,
Shows a SnackBar across all registered Scaffolds but instead of SnackBar widget, you can just give it a string.
Implementation
void showToast({
required String text,
Duration? duration,
SnackBarAction? action,
TextStyle? textStyle,
Color? backgroundColor,
SnackBarBehavior? behavior,
bool hideCurrentSnackbar = true,
}) {
if (hideCurrentSnackbar) {
ScaffoldMessenger.of(this).hideCurrentSnackBar();
}
ScaffoldMessenger.of(this).showSnackBar(
SnackBar(
content: Text(
text,
style: textStyle,
),
backgroundColor: backgroundColor,
duration: duration ?? const Duration(seconds: 5),
action: action,
behavior: behavior,
),
);
}