show static method

void show(
  1. BuildContext context, {
  2. required String message,
  3. Duration duration = const Duration(seconds: 2),
  4. Color? backgroundColor,
  5. Color? textColor,
})

Shows a toast message via the Overlay.

The toast appears at the bottom of the screen and is automatically removed after duration elapses.

Implementation

static void show(
  BuildContext context, {
  required String message,
  Duration duration = const Duration(seconds: 2),
  Color? backgroundColor,
  Color? textColor,
}) {
  final overlay = Overlay.of(context);
  if (overlay == null) return;

  final entry = _buildOverlayEntry(
    message,
    backgroundColor: backgroundColor,
    textColor: textColor,
  );

  overlay.insert(entry);
  Future.delayed(duration, () {
    if (entry.mounted) entry.remove();
  });
}