show static method

void show({
  1. required BuildContext context,
  2. required String message,
  3. Widget? icon,
  4. CNToastPosition position = CNToastPosition.center,
  5. CNToastDuration duration = CNToastDuration.medium,
  6. CNToastStyle style = CNToastStyle.normal,
  7. Color? backgroundColor,
  8. Color? textColor,
  9. bool useGlassEffect = true,
})

Shows a toast with the given message.

Implementation

static void show({
  required BuildContext context,
  required String message,
  Widget? icon,
  CNToastPosition position = CNToastPosition.center,
  CNToastDuration duration = CNToastDuration.medium,
  CNToastStyle style = CNToastStyle.normal,
  Color? backgroundColor,
  Color? textColor,
  bool useGlassEffect = true,
}) {
  // Resolve the OverlayState eagerly from the caller's live context.
  // We store the OverlayState — not the BuildContext — on the queued
  // entry so a later `_showNext()` firing from a Timer can never
  // dereference a deactivated caller widget (Issue #46 bug A).
  final overlay = Overlay.of(context);

  _queue.add(
    _ToastEntry(
      overlay: overlay,
      message: message,
      icon: icon,
      position: position,
      duration: duration,
      style: style,
      backgroundColor: backgroundColor,
      textColor: textColor,
      useGlassEffect: useGlassEffect,
    ),
  );

  if (!_isShowing) {
    _showNext();
  }
}