showToast function

ToastOverlay showToast({
  1. required BuildContext context,
  2. required ToastBuilder builder,
  3. ToastLocation location = ToastLocation.bottomRight,
  4. bool dismissible = true,
  5. Curve curve = Curves.easeOutCubic,
  6. Duration entryDuration = const Duration(milliseconds: 500),
  7. VoidCallback? onClosed,
  8. 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);
}