toast static method

Future<void> toast(
  1. String message, {
  2. ToastPosition position = ToastPosition.bottom,
  3. ToastType type = ToastType.scale,
  4. Duration duration = const Duration(milliseconds: 2500),
  5. Duration? delay,
  6. IconData? icon,
  7. Color? color,
  8. bool lastToastShownAt = false,
  9. Offset? customOffset,
  10. Widget? child,
})

Implementation

static Future<void> toast(
    String message, {
      ToastPosition position = ToastPosition.bottom,
      ToastType type = ToastType.scale,
      Duration duration = const Duration(milliseconds: 2500),
      Duration? delay,
      IconData? icon,
      Color? color,
      bool lastToastShownAt = false,
      Offset? customOffset,
      Widget? child

    }) async {
  if(delay != null) {
    await Future.delayed(delay);
  }

  if(lastToastShownAt) {
    if (_isShowing) return;
  }
  _isShowing = true;

  final overlay = NavigationService.defaultKey.currentState?.overlay;
  if (overlay == null) {
    _isShowing = false;
    return;
  }

  late OverlayEntry overlayEntry;
  overlayEntry = OverlayEntry(
    builder: (_) => AnimatedSnackbar(
      message: message,
      position: position,
      type: type,
      icon: icon,
      color: color,
      duration: duration,
      customOffset: customOffset,
      child: child,
      onClose: () {
        // remove safely
        if (overlayEntry.mounted) overlayEntry.remove();
        _isShowing = false;
      },
    ),
  );

  overlay.insert(overlayEntry);
}