showToast function
ToastOverlay
showToast({
- required BuildContext context,
- required ToastBuilder builder,
- ToastLocation location = ToastLocation.bottomRight,
- bool dismissible = true,
- Curve curve = Curves.easeOutCubic,
- Duration entryDuration = const Duration(milliseconds: 500),
- VoidCallback? onClosed,
- Duration showDuration = const Duration(seconds: 5),
Implementation
ToastOverlay showToast({
required BuildContext context,
required ToastBuilder builder,
ToastLocation location = ToastLocation.bottomRight,
bool dismissible = true,
Curve curve = Curves.easeOutCubic,
Duration entryDuration = const Duration(milliseconds: 500),
VoidCallback? onClosed,
Duration showDuration = const Duration(seconds: 5),
}) {
_ToastLayerState? layer = Data.maybeFindMessenger(context);
layer ??= Data.maybeOf(context);
CapturedThemes? themes;
CapturedData? data;
if (layer != null) {
themes = InheritedTheme.capture(from: context, to: layer.context);
data = Data.capture(from: context, to: layer.context);
} else {
layer = Data.maybeFindMessenger<_ToastLayerState>(context);
}
assert(layer != null, 'No ToastLayer found in context');
final entry = ToastEntry(
builder: builder,
location: location,
dismissible: dismissible,
curve: curve,
duration: entryDuration,
themes: themes,
data: data,
onClosed: onClosed,
showDuration: showDuration,
);
return layer!.addEntry(entry);
}