showToastWidget function

Future<void> showToastWidget(
  1. {required Toast toast,
  2. required BuildContext context}
)

Show a toast widget

Implementation

Future<void> showToastWidget({
  required Toast toast,
  required BuildContext context,
}) async {
  final entry = OverlayEntry(builder: (context) => toast);

  assert(debugCheckHasOverlay(context));
  Overlay.of(context).insert(entry);

  ToastManager.insert(entry);

  await Future.delayed(
    (toast.duration ?? kDefaultToastDuration) +
        (toast.animationDuration ?? kDefaultToastAnimationDuration) * 2,
    () {
      ToastManager.dismiss(entry);
      toast.onDismiss?.call();
    },
  );
}