showFToast function

FToasterEntry showFToast({
  1. required BuildContext context,
  2. required Widget title,
  3. FToastStyleDelta style = const .context(),
  4. Widget? icon,
  5. Widget? description,
  6. Widget suffixBuilder(
    1. BuildContext context,
    2. FToasterEntry entry
    )?,
  7. FToastAlignment? alignment,
  8. List<AxisDirection>? swipeToDismiss,
  9. double dismissThreshold = 0.5,
  10. Duration? duration = const Duration(seconds: 5),
  11. VoidCallback? onDismiss,
})

Displays a FToast in a toaster.

alignment defaults to FToasterStyle.toastAlignment.

swipeToDismiss represents axes in which to swipe to dismiss a toast. Defaults to horizontally towards the closest edge of the screen with a left bias. For example, if alignment is FToastAlignment.bottomRight, the default swipe direction is AxisDirection.right.

Set swipeToDismiss to an empty list to disable swiping to dismiss.

dismissThreshold is the fraction of the toast's width/height that must be swiped before the toast is dismissed. The higher the threshold, the more the user has to swipe to dismiss the toast. Defaults to 0.5.

duration controls the duration which the toast is shown. Defaults to 5 seconds. Set duration to null to disable auto-dismissing.

Contract

Throws an error if:

  • there is no ancestor FToaster in the given context.
  • dismissThreshold is not in the range [0, 1].

See:

Implementation

FToasterEntry showFToast({
  required BuildContext context,
  required Widget title,
  FToastStyleDelta style = const .context(),
  Widget? icon,
  Widget? description,
  Widget Function(BuildContext context, FToasterEntry entry)? suffixBuilder,
  FToastAlignment? alignment,
  List<AxisDirection>? swipeToDismiss,
  double dismissThreshold = 0.5,
  Duration? duration = const Duration(seconds: 5),
  VoidCallback? onDismiss,
}) {
  final state = context.findAncestorStateOfType<FToasterState>();
  if (state == null) {
    throw FlutterError.fromParts([
      ErrorSummary('showFToast(...) called with a context that does not contain a FToaster.'),
      ErrorDescription(
        'No FToaster ancestor could be found starting from the context that was passed to showFToast(...). '
        'This usually happens when the context provided is from the same StatefulWidget as that whose build function '
        'actually creates the FToaster widget being sought.',
      ),
      ErrorHint(
        'There are several ways to avoid this problem. The simplest is to use a Builder to get a '
        'context that is "under" the FToaster.',
      ),
      context.describeElement('The context used was'),
    ]);
  }

  return state.show(
    context: context,
    builder: (context, entry) => FToast(
      style: style,
      icon: icon,
      title: title,
      description: description,
      suffix: suffixBuilder?.call(context, entry),
    ),
    style: style,
    alignment: alignment,
    swipeToDismiss: swipeToDismiss,
    dismissThreshold: dismissThreshold,
    duration: duration,
    onDismiss: onDismiss,
  );
}