A smart, context-aware toast notification package for Flutter that automatically detects message types and displays appropriately styled notifications.

Features

  • Automatic detection of message type (success, error, warning, info) based on content.
  • Custom styling based on message type (colors and icons).
  • Support for custom action buttons with callbacks.
  • Customizable display duration.
  • Override options for background color, type, and actions.

Getting Started

To add smart_toast to your project, include it in your pubspec.yaml:

dependencies:
  smart_toast: ^1.0.4

Run:

flutter pub get

Usage

import 'package:smart_toast/smart_toast.dart';

// Simple usage with auto-detection use it inside some buttton
SmartToast.show(context, "Operation successful!");

// Error message (will automatically use error styling) use it inside some buttton
SmartToast.show(context, "Failed to load data");

// With custom action use it inside some buttton
SmartToast.show(
  context, 
  "Profile updated successfully", 
  actionLabel: "View Profile",
  onActionPressed: () {
    Navigator.pushNamed(context, '/profile');
  }
);

// With custom duration and background color use it inside some buttton
SmartToast.show(
  context, 
  "Custom colored toast", 
  backgroundColor: Colors.purple,
  duration: const Duration(seconds: 5)
);

 // Show warning toast with custom message and action use it inside some button
                 SmartToast.show(
                  context, 
                  "Updated", 
                  overrideType: ToastType.success,
                  actionLabel: "Undo",
                  onActionPressed: () {
                    // Custom action when button is pressed
                    print("Undo action pressed!");
                  },
                  duration: Duration(seconds: 5),
                  backgroundColor: Colors.green,
                );

These are the some visual images of some type:-

This is for the auto detection if it contains some words like error , warn, success all these 3 words will enerate a different type of toast here . Error will generate a red , Warn will generate a yellow and Success will generate a green toast.

ElevatedButton(
  onPressed: () {
    SmartToast.show(context, "UnexpectedError"); // Will show error style
  },
  child: Text("Fetch Data"),
)

SmartToast Error Toast

Or you can generate a customized toast like :-

    SmartToast.show(
                  context, 
                  "Updated", 
                  overrideType: ToastType.success,
                  actionLabel: "Undo",
                  onActionPressed: () {
                    // Custom action when button is pressed
                    print("Undo action pressed!");
                  },
                  duration: Duration(seconds: 5),
                  backgroundColor: Colors.green,
                );

SmartToast Success Toast

Additional information

Auto-detection Mechanism

SmartToast intelligently detects the type of notification by analyzing the message content:

static ToastType _detectType(String message) {
  final lower = message.toLowerCase();
  if (lower.contains("error") || lower.contains("failed")) return ToastType.error;
  if (lower.contains("success") || lower.contains("done") || lower.contains("updated")) return ToastType.success;
  if (lower.contains("warn") || lower.contains("caution") || lower.contains("oops")) return ToastType.warning;
  return ToastType.info;
}

Libraries

smart_toast