showToastWidget function
ToastFuture
showToastWidget(
- Widget widget, {
- BuildContext? context,
- Duration? duration,
- Duration? animDuration,
- VoidCallback? onDismiss,
- bool? dismissOtherToast,
- TextDirection? textDirection,
- Alignment? alignment,
- Axis? axis,
- Offset? startOffset,
- Offset? endOffset,
- Offset? reverseStartOffset,
- Offset? reverseEndOffset,
- StyledToastPosition? position,
- StyledToastAnimation? animation,
- StyledToastAnimation? reverseAnimation,
- Curve? curve,
- Curve? reverseCurve,
- bool? isHideKeyboard,
- CustomAnimationBuilder? animationBuilder,
- CustomAnimationBuilder? reverseAnimBuilder,
- bool? isIgnoring,
- OnInitStateCallback? onInitState,
Show custom content widget for toasting.
Implementation
ToastFuture showToastWidget(
Widget widget, {
BuildContext? context,
Duration? duration,
Duration? animDuration,
VoidCallback? onDismiss,
bool? dismissOtherToast,
TextDirection? textDirection,
Alignment? alignment,
Axis? axis,
Offset? startOffset,
Offset? endOffset,
Offset? reverseStartOffset,
Offset? reverseEndOffset,
StyledToastPosition? position,
StyledToastAnimation? animation,
StyledToastAnimation? reverseAnimation,
Curve? curve,
Curve? reverseCurve,
bool? isHideKeyboard,
CustomAnimationBuilder? animationBuilder,
CustomAnimationBuilder? reverseAnimBuilder,
bool? isIgnoring,
OnInitStateCallback? onInitState,
}) {
OverlayEntry entry;
ToastFuture future;
context ??= currentContext;
assert(context != null);
final toastTheme = StyledToastTheme.maybeOf(context!);
isHideKeyboard ??= toastTheme?.isHideKeyboard ?? false;
duration ??= toastTheme?.duration ?? _defaultDuration;
animDuration ??= toastTheme?.animDuration ?? animationDuration;
dismissOtherToast ??= toastTheme?.dismissOtherOnShow ?? true;
textDirection ??=
textDirection ?? toastTheme?.textDirection ?? TextDirection.ltr;
position ??= toastTheme?.toastPositions ?? StyledToastPosition.bottom;
alignment ??= toastTheme?.alignment ?? Alignment.center;
axis ??= toastTheme?.axis ?? Axis.vertical;
startOffset ??= toastTheme?.startOffset;
endOffset ??= toastTheme?.endOffset;
reverseStartOffset ??= toastTheme?.reverseStartOffset;
reverseEndOffset ??= toastTheme?.reverseEndOffset;
curve ??= curve ?? toastTheme?.curve ?? Curves.linear;
reverseCurve ??= reverseCurve ?? toastTheme?.reverseCurve ?? Curves.linear;
animation ??=
animation ?? toastTheme?.toastAnimation ?? StyledToastAnimation.size;
reverseAnimation ??= reverseAnimation ??
toastTheme?.reverseAnimation ??
StyledToastAnimation.size;
animationBuilder ??= animationBuilder ?? toastTheme?.animationBuilder;
reverseAnimBuilder ??= reverseAnimBuilder ?? toastTheme?.reverseAnimBuilder;
onInitState ??= onInitState ?? toastTheme?.onInitState;
onDismiss ??= onDismiss ?? toastTheme?.onDismiss;
isIgnoring ??= toastTheme?.isIgnoring ?? true;
if (isHideKeyboard) {
/// Hide keyboard.
FocusScope.of(context).requestFocus(FocusNode());
}
GlobalKey<StyledToastWidgetState> key = GlobalKey();
entry = OverlayEntry(builder: (ctx) {
return IgnorePointer(
ignoring: isIgnoring!,
child: _StyledToastWidget(
duration: duration!,
animDuration: animDuration!,
position: position,
animation: animation,
reverseAnimation: reverseAnimation,
alignment: alignment,
axis: axis,
startOffset: startOffset,
endOffset: endOffset,
reverseStartOffset: reverseStartOffset,
reverseEndOffset: reverseEndOffset,
curve: curve!,
reverseCurve: reverseCurve!,
key: key,
animationBuilder: animationBuilder,
reverseAnimBuilder: reverseAnimBuilder,
onInitState: onInitState,
child: Directionality(
textDirection: textDirection!,
child: Material(
child: widget,
color: Colors.transparent,
),
),
),
);
});
if (dismissOtherToast) {
dismissAllToast();
}
future = ToastFuture.create(duration, entry, onDismiss, key);
Overlay.of(context).insert(entry);
ToastManager().addFuture(future);
return future;
}