show static method

void show(
  1. BuildContext context,
  2. String message, {
  3. Duration duration = const Duration(seconds: 2),
  4. Color? backgroundColor,
  5. Color? textColor,
  6. IconData? icon,
  7. Map<String, dynamic>? metadata,
})

Shows a customizable toast notification.

context - The build context. message - The text message to display. duration - How long the toast should be visible. Defaults to 2 seconds. backgroundColor - Custom background color. textColor - Custom text color. icon - Optional icon to display. metadata - Optional metadata logger.

Implementation

static void show(
  BuildContext context,
  String message, {
  Duration duration = const Duration(seconds: 2),
  Color? backgroundColor,
  Color? textColor,
  IconData? icon,
  Map<String, dynamic>? metadata,
}) {
  // Log the toast
  _logger.logToast(message, metadata: metadata);

  // Remove existing toast
  _currentToast?.remove();

  final overlay = Overlay.of(context);

  _currentToast = OverlayEntry(
    builder: (context) => _ToastWidget(
      message: message,
      backgroundColor: backgroundColor,
      textColor: textColor,
      icon: icon,
    ),
  );

  overlay.insert(_currentToast!);

  Future.delayed(duration, () {
    _currentToast?.remove();
    _currentToast = null;
  });
}