show method

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

Displays a toast in this toaster.

dismissThreshold is the fraction of the toast's width/height that must be swiped before the toast is dismissed. Defaults to 0.5.

It is generally recommend to use showFToast or showRawFToast instead.

See showRawFToast for more information about the parameters.

Implementation

FToasterEntry show({
  required Widget Function(BuildContext context, FToasterEntry entry) builder,
  BuildContext? context,
  FToastStyleDelta style = const .context(),
  FToastAlignment? alignment,
  List<AxisDirection>? swipeToDismiss,
  double dismissThreshold = 0.5,
  Duration? duration = const Duration(seconds: 5),
  VoidCallback? onDismiss,
}) {
  assert(0 <= dismissThreshold && dismissThreshold <= 1);
  context ??= this.context;

  final direction = Directionality.maybeOf(context) ?? .ltr;
  final toasterStyle = widget.style(context.theme.toasterStyle);
  final resolved = (alignment ?? toasterStyle.toastAlignment)._alignment.resolve(direction);
  final directions = swipeToDismiss ?? [if (resolved.x < 1) .left else .right];

  final entry = ToasterEntry(
    style(toasterStyle.toastStyle),
    resolved,
    directions,
    dismissThreshold,
    duration,
    builder,
  );
  entry.onDismiss = () {
    entry.dismissing.value = true;
    _remove(entry);
    onDismiss?.call();
  };

  if (!mounted) {
    return entry;
  }

  setState(() {
    final (_, entries) = _entries[resolved] ??= ((alignment ?? toasterStyle.toastAlignment)._toastAlignment, []);
    entries.add(entry);
  });

  return entry;
}