showToast function

ToastFuture showToast(
  1. String? msg, {
  2. BuildContext? context,
  3. Duration? duration,
  4. Duration? animDuration,
  5. StyledToastPosition? position,
  6. TextStyle? textStyle,
  7. EdgeInsetsGeometry? textPadding,
  8. double toastHorizontalMargin = _defaultHorizontalMargin,
  9. Color? backgroundColor,
  10. BorderRadius? borderRadius,
  11. ShapeBorder? shapeBorder,
  12. VoidCallback? onDismiss,
  13. TextDirection? textDirection,
  14. bool? dismissOtherToast,
  15. StyledToastAnimation? animation,
  16. StyledToastAnimation? reverseAnimation,
  17. Alignment? alignment,
  18. Axis? axis,
  19. Offset? startOffset,
  20. Offset? endOffset,
  21. Offset? reverseStartOffset,
  22. Offset? reverseEndOffset,
  23. TextAlign? textAlign,
  24. Curve? curve,
  25. Curve? reverseCurve,
  26. bool? fullWidth,
  27. bool? isHideKeyboard,
  28. CustomAnimationBuilder? animationBuilder,
  29. CustomAnimationBuilder? reverseAnimBuilder,
  30. bool? isIgnoring,
  31. OnInitStateCallback? onInitState,
})

Show normal toast with style and animation.

Can be used without wrapping you app with StyledToast, but must specify context, When you wrap your app with StyledToast, context is optional, animationBuilder If not null, animation is not working, reverseAnimBuilder If not null, reverseAnimation is not working.

Implementation

ToastFuture showToast(
  final String? msg, {
  BuildContext? context,
  final Duration? duration,
  final Duration? animDuration,
  StyledToastPosition? position,
  TextStyle? textStyle,
  EdgeInsetsGeometry? textPadding,
  final double toastHorizontalMargin = _defaultHorizontalMargin,
  Color? backgroundColor,
  BorderRadius? borderRadius,
  ShapeBorder? shapeBorder,
  final VoidCallback? onDismiss,
  TextDirection? textDirection,
  final bool? dismissOtherToast,
  final StyledToastAnimation? animation,
  final StyledToastAnimation? reverseAnimation,
  final Alignment? alignment,
  final Axis? axis,
  final Offset? startOffset,
  final Offset? endOffset,
  final Offset? reverseStartOffset,
  final Offset? reverseEndOffset,
  TextAlign? textAlign,
  final Curve? curve,
  final Curve? reverseCurve,
  bool? fullWidth,
  final bool? isHideKeyboard,
  final CustomAnimationBuilder? animationBuilder,
  final CustomAnimationBuilder? reverseAnimBuilder,
  final bool? isIgnoring,
  final OnInitStateCallback? onInitState,
}) {
  context ??= currentContext;
  assert(context != null);

  final toastTheme = StyledToastTheme.maybeOf(context!);

  position ??= toastTheme?.toastPositions ?? StyledToastPosition.bottom;

  textStyle ??= toastTheme?.textStyle ??
      const TextStyle(fontSize: 16.0, color: Colors.white);

  textPadding ??= toastTheme?.textPadding ??
      const EdgeInsets.symmetric(horizontal: 17.0, vertical: 10.0);

  backgroundColor ??= toastTheme?.backgroundColor ?? const Color(0x99000000);
  borderRadius ??= toastTheme?.borderRadius ?? BorderRadius.circular(5.0);

  shapeBorder ??= toastTheme?.shapeBorder ??
      RoundedRectangleBorder(
        borderRadius: borderRadius,
      );

  textDirection ??= toastTheme?.textDirection ?? TextDirection.ltr;

  textAlign ??= toastTheme?.textAlign ?? TextAlign.center;

  fullWidth ??= toastTheme?.fullWidth ?? false;

  final widget = Container(
    margin: EdgeInsets.symmetric(horizontal: toastHorizontalMargin),
    width: fullWidth
        ? MediaQuery.of(context).size.width - (toastHorizontalMargin)
        : null,
    decoration: ShapeDecoration(
      color: backgroundColor,
      shape: shapeBorder,
    ),
    padding: textPadding,
    child: Text(
      msg ?? '',
      style: textStyle,
      textAlign: textAlign,
    ),
  );

  return showToastWidget(
    widget,
    context: context,
    duration: duration,
    animDuration: animDuration,
    onDismiss: onDismiss,
    position: position,
    dismissOtherToast: dismissOtherToast,
    textDirection: textDirection,
    alignment: alignment,
    axis: axis,
    startOffset: startOffset,
    endOffset: endOffset,
    reverseStartOffset: reverseStartOffset,
    reverseEndOffset: reverseEndOffset,
    curve: curve,
    reverseCurve: reverseCurve,
    animation: animation,
    reverseAnimation: reverseAnimation,
    isHideKeyboard: isHideKeyboard,
    animationBuilder: animationBuilder,
    reverseAnimBuilder: reverseAnimBuilder,
    isIgnoring: isIgnoring,
    onInitState: onInitState,
  );
}