showCustom method
ToastificationItem
showCustom({
- BuildContext? context,
- AlignmentGeometry? alignment,
- TextDirection? direction,
- required ToastificationBuilder builder,
- ToastificationAnimationBuilder? animationBuilder,
- Duration? animationDuration,
- Duration? autoCloseDuration,
- OverlayState? overlayState,
- DismissDirection? dismissDirection,
- ToastificationCallbacks callbacks = const ToastificationCallbacks(),
shows a custom notification
you should create your own widget and pass it to the builder parameter
in the builder parameter you have the access to ToastificationItem
so you may want to use that to create your widget.
the return value is a ToastificationItem that you can use to dismiss the notification
or find the notification details by its id
example :
toastification.showCustom(
context: context, // optional if ToastificationWrapper is in widget tree
alignment: Alignment.topRight,
animationDuration: Duration(milliseconds: 500),
autoCloseDuration: Duration(seconds: 3),
builder: (context, item) {
return CustomToastWidget();
},
);
Implementation
ToastificationItem showCustom({
BuildContext? context,
AlignmentGeometry? alignment,
TextDirection? direction,
required ToastificationBuilder builder,
ToastificationAnimationBuilder? animationBuilder,
Duration? animationDuration,
Duration? autoCloseDuration,
OverlayState? overlayState,
DismissDirection? dismissDirection,
ToastificationCallbacks callbacks = const ToastificationCallbacks(),
}) {
context ??= overlayState?.context;
final contextProvided = context?.mounted == true;
if (contextProvided) {
direction ??= Directionality.of(context!);
overlayState ??= Overlay.maybeOf(context!, rootOverlay: true);
}
/// if context isn't provided
/// or the overlay can't be found in the provided context
ToastificationOverlayState? toastificationOverlayState;
if (overlayState == null) {
toastificationOverlayState = findToastificationOverlayState();
overlayState = toastificationOverlayState.overlayState;
}
/// find the config from the context or use the global config
final ToastificationConfig config = (contextProvided
? ToastificationConfigProvider.maybeOf(context!)?.config
: toastificationOverlayState?.globalConfig) ??
const ToastificationConfig();
direction ??= TextDirection.ltr;
final effectiveAlignment =
(alignment ?? config.alignment).resolve(direction);
final manager = managers.putIfAbsent(
effectiveAlignment,
() => ToastificationManager(
alignment: effectiveAlignment,
config: config,
),
);
return manager.showCustom(
builder: builder,
scheduler: SchedulerBinding.instance,
animationBuilder: animationBuilder,
animationDuration: animationDuration,
autoCloseDuration: autoCloseDuration,
overlayState: overlayState!,
callbacks: callbacks,
);
}