custom static method

void custom(
  1. BuildContext context, {
  2. required String message,
  3. required Color backgroundColor,
  4. ToastPosition? position,
  5. Color textColor = Colors.white,
  6. IconData? icon,
  7. Duration? duration,
  8. bool? showCloseButton,
  9. ToastBehavior? behavior,
  10. VoidCallback? onTap,
})

Show custom toast with custom colors

Implementation

static void custom(
  BuildContext context, {
  required String message,
  required Color backgroundColor,
  ToastPosition? position,
  Color textColor = Colors.white,
  IconData? icon,
  Duration? duration,
  bool? showCloseButton,
  ToastBehavior? behavior,
  VoidCallback? onTap,
}) {
  final config = defaultConfig;
  final finalPosition = position ?? config.position;
  final finalDuration = duration ?? config.duration;
  final finalShowCloseButton = showCloseButton ?? config.showCloseButton;
  final finalBehavior = behavior ?? config.behavior;

  if (finalBehavior == ToastBehavior.queue) {
    _ToastQueue.enqueue(_ToastItem(
      context: context,
      message: message,
      type: ToastType.info, // Dummy type for custom
      position: finalPosition,
      animation: config.animation,
      backgroundColor: backgroundColor,
      textColor: textColor,
      textStyle: TextStyle(
        color: textColor,
        fontWeight: FontWeight.w500,
        fontSize: 14,
      ),
      showIcon: icon != null,
      showCloseButton: finalShowCloseButton,
      elevation: config.elevation,
      borderRadius: config.borderRadius,
      maxWidth: config.maxWidth,
      margin: config.margin,
      padding: config.padding,
      duration: finalDuration,
      onTap: onTap,
      customIcon: icon,
    ));
    return;
  }

  _showToastDirect(
    context,
    message: message,
    type: ToastType.info,
    position: finalPosition,
    animation: config.animation,
    duration: finalDuration,
    backgroundColor: backgroundColor,
    textColor: textColor,
    textStyle: TextStyle(
      color: textColor,
      fontWeight: FontWeight.w500,
      fontSize: 14,
    ),
    showIcon: icon != null,
    showCloseButton: finalShowCloseButton,
    elevation: config.elevation,
    borderRadius: config.borderRadius,
    maxWidth: config.maxWidth,
    margin: config.margin,
    padding: config.padding,
    onTap: onTap,
    customIcon: icon,
  );
}