showToast function
void
showToast(
- BuildContext context,
- String message, {
- Duration duration = const Duration(seconds: 2),
- Alignment alignment = Alignment.bottomCenter,
- TextStyle? textStyle,
- BoxDecoration? background,
- EdgeInsets? padding,
- Offset? offsetAnimationStart,
Displays the toast.
The only method which is called. Only the context
and message
are
required, the rest is optional.
Implementation
void showToast(
BuildContext context,
String message, {
Duration duration = const Duration(seconds: 2),
Alignment alignment = Alignment.bottomCenter,
TextStyle? textStyle,
BoxDecoration? background,
EdgeInsets? padding,
Offset? offsetAnimationStart,
}) {
// Only initialize once. I *think* this is safe to do.
_overlayState ??= Overlay.of(context);
_toastWithCorrespondingOverlayEntry.forEach((key, value) {
key.hide();
});
final ToastWidget toast = ToastWidget(
message: message,
duration: duration,
alignment: alignment,
textStyle: textStyle,
background: background,
padding: padding,
offsetAnimationStart: offsetAnimationStart,
);
final OverlayEntry overlayEntry =
OverlayEntry(builder: (BuildContext context) => toast);
_overlayState!.insert(overlayEntry);
_toastWithCorrespondingOverlayEntry[toast] = overlayEntry;
}