showToastWidget function

ToastFuture showToastWidget (
  1. Widget widget,
  2. {BuildContext context,
  3. Duration duration,
  4. ToastPosition position,
  5. VoidCallback onDismiss,
  6. bool dismissOtherToast,
  7. TextDirection textDirection,
  8. bool handleTouch,
  9. OKToastAnimationBuilder animationBuilder,
  10. Duration animationDuration,
  11. Curve animationCurve}
)

show widget with oktoast

Implementation

ToastFuture showToastWidget(
  Widget widget, {
  BuildContext context,
  Duration duration,
  ToastPosition position,
  VoidCallback onDismiss,
  bool dismissOtherToast,
  TextDirection textDirection,
  bool handleTouch,
  OKToastAnimationBuilder animationBuilder,
  Duration animationDuration,
  Curve animationCurve,
}) {
  context ??= _contextMap.values.first;
  OverlayEntry entry;
  ToastFuture future;
  final theme = _ToastTheme.of(context);

  position ??= theme.position;
  handleTouch ??= theme.handleTouch;
  animationBuilder ??= theme.animationBuilder;
  animationDuration ??=
      theme.animationDuration ?? const Duration(milliseconds: 250);
  animationCurve ??= theme.animationCurve ?? Curves.easeIn;
  duration ??= theme.duration ?? _defaultDuration;

  final movingOnWindowChange = theme?.movingOnWindowChange ?? false;

  final direction = textDirection ?? theme.textDirection ?? TextDirection.ltr;

  GlobalKey<__ToastContainerState> key = GlobalKey();

  widget = Align(
    child: widget,
    alignment: position.align,
  );

  entry = OverlayEntry(builder: (ctx) {
    return IgnorePointer(
      ignoring: !handleTouch,
      child: Directionality(
        textDirection: direction,
        child: _ToastContainer(
          duration: duration,
          position: position,
          movingOnWindowChange: movingOnWindowChange,
          key: key,
          child: widget,
          animationBuilder: animationBuilder,
          animationDuration: animationDuration,
          animationCurve: animationCurve,
        ),
      ),
    );
  });

  dismissOtherToast ??= theme.dismissOtherOnShow ?? false;

  if (dismissOtherToast == true) {
    ToastManager().dismissAll();
  }

  future = ToastFuture._(entry, onDismiss, key, animationDuration);

  Future.delayed(duration, () {
    future.dismiss();
  });

  Overlay.of(context).insert(entry);
  ToastManager().addFuture(future);

  return future;
}