showToast method

void showToast({
  1. required Widget child,
  2. required PositionedToastBuilder positionedToastBuilder,
  3. Duration toastDuration = const Duration(seconds: 2),
  4. ToastGravity? gravity,
  5. int fadeDuration = 350,
})

showToast accepts all the required paramenters and prepares the child calls _showOverlay to display toast

Paramenter child is requried fadeDuration default is 350 milliseconds

Implementation

void showToast({
  required Widget child,
  required PositionedToastBuilder positionedToastBuilder,
  Duration toastDuration = const Duration(seconds: 2),
  ToastGravity? gravity,
  int fadeDuration = 350,
}) {
  if (context == null) {
    throw 'Error: Context is null, Please call init(context) before showing toast.';
  }
  final Widget newChild = _ToastStateFul(
    child,
    toastDuration,
    animationDuration: fadeDuration,
  );

  /// Check for keyboard open
  /// If open will ignore the gravity bottom and change it to center
  if (gravity == ToastGravity.bottom) {
    if (MediaQuery.of(context!).viewInsets.bottom != 0) {
      // ignore: parameter_assignments
      gravity = ToastGravity.center;
    }
  }

  final OverlayEntry newEntry = OverlayEntry(
    builder: (context) {
      return positionedToastBuilder(context, newChild);
    },
  );

  _overlayQueue.add(
    _ToastEntry(
      entry: newEntry,
      duration: toastDuration,
    ),
  );
  if (_timer == null) _showOverlay();
}