showToast method

void showToast({
  1. required BuildContext context,
  2. required String text,
  3. UpStyle? style,
  4. UpColorType? upColorType,
  5. bool isRounded = false,
  6. double borderRadius = 25.0,
  7. UpToastType upToastType = UpToastType.primary,
  8. EdgeInsetsGeometry? padding,
  9. Icon? icon,
  10. Duration? duration,
  11. double width = 300,
  12. double? height,
})

Implementation

void showToast({
  required BuildContext context,
  required String text,
  UpStyle? style,
  UpColorType? upColorType,
  bool isRounded = false,
  double borderRadius = 25.0,
  UpToastType upToastType = UpToastType.primary,
  EdgeInsetsGeometry? padding,
  Icon? icon,
  Duration? duration,
  double width = 300,
  double? height,
}) async {
  if (_isVisible) {
    return;
  }

  _isVisible = true;

  final OverlayState overlayState = Overlay.of(context);
  final OverlayEntry overlayEntry = OverlayEntry(
    builder: (BuildContext context) => _UpToast(
      style: style,
      colorType: upColorType,
      text: text,
      isRounded: isRounded,
      borderRadius: borderRadius,
      upToastType: upToastType,
      icon: icon,
      padding: padding,
      width: width,
      height: height,
    ),
  );
  overlayState.insert(overlayEntry);

  await Future.delayed(duration ?? const Duration(seconds: 2));

  overlayEntry.remove();

  _isVisible = false;
}