showToast function
ToastFuture
showToast(
- String? msg, {
- BuildContext? context,
- Duration? duration,
- Duration? animDuration,
- StyledToastPosition? position,
- TextStyle? textStyle,
- EdgeInsetsGeometry? textPadding,
- double toastHorizontalMargin = _defaultHorizontalMargin,
- Color? backgroundColor,
- BorderRadius? borderRadius,
- ShapeBorder? shapeBorder,
- VoidCallback? onDismiss,
- TextDirection? textDirection,
- bool? dismissOtherToast,
- StyledToastAnimation? animation,
- StyledToastAnimation? reverseAnimation,
- Alignment? alignment,
- Axis? axis,
- Offset? startOffset,
- Offset? endOffset,
- Offset? reverseStartOffset,
- Offset? reverseEndOffset,
- TextAlign? textAlign,
- Curve? curve,
- Curve? reverseCurve,
- bool? fullWidth,
- bool? isHideKeyboard,
- CustomAnimationBuilder? animationBuilder,
- CustomAnimationBuilder? reverseAnimBuilder,
- bool? isIgnoring,
- 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(
builder: (context, theme) => 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,
);
}