showFToast function

FToasterEntry showFToast({
  1. required BuildContext context,
  2. required Widget title,
  3. FToastStyle? style,
  4. Widget? icon,
  5. Widget? description,
  6. ValueWidgetBuilder<FToasterEntry>? suffixBuilder,
  7. FToastAlignment alignment = FToastAlignment.bottomEnd,
  8. Duration? duration = const Duration(seconds: 5),
  9. VoidCallback? onDismiss,
})

Displays a FToast in a toaster.

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

Contract

Throws FlutterError if there is no ancestor FToaster in the given context.

See:

Implementation

FToasterEntry showFToast({
  required BuildContext context,
  required Widget title,
  FToastStyle? style,
  Widget? icon,
  Widget? description,
  ValueWidgetBuilder<FToasterEntry>? suffixBuilder,
  FToastAlignment alignment = FToastAlignment.bottomEnd,
  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/FScaffold.'),
      ErrorDescription(
        'No FToaster/FScaffold ancestor could be found starting from the context that was passed to FToaster/FScaffold.of(). '
        'This usually happens when the context provided is from the same StatefulWidget as that whose build function '
        'actually creates the FToaster/FScaffold 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/FScaffold.',
      ),
      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, null),
    ),
    style: style,
    alignment: alignment,
    duration: duration,
    onDismiss: onDismiss,
  );
}