show method

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

Displays a toast in this toaster.

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,
  FToastStyle Function(FToastStyle style)? style,
  FToastAlignment? alignment,
  List<AxisDirection>? swipeToDismiss,
  Duration? duration = const Duration(seconds: 5),
  VoidCallback? onDismiss,
}) {
  context ??= this.context;

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

  final entry = ToasterEntry(
    style?.call(toasterStyle.toastStyle) ?? toasterStyle.toastStyle,
    resolved,
    directions,
    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;
}