modern_toast 0.0.5 copy "modern_toast: ^0.0.5" to clipboard
modern_toast: ^0.0.5 copied to clipboard

A beautiful, modern, and customizable toast notification package for Flutter with smooth animations and multiple toast types.

Modern Toast #

A beautiful, modern, and highly customizable toast notification package for Flutter with smooth animations, multiple toast types, and advanced customization options.

โœจ Features #

  • ๐ŸŽจ 4 Pre-defined Toast Types: Success, Error, Warning, and Info with beautiful colors
  • ๐ŸŽญ Smooth Animations: Zoom-in and slide-down animations using animate_do
  • ๐ŸŽฏ Customizable: Create your own custom toasts with custom colors, icons, and text styles
  • ๐Ÿ“ฑ Responsive Design: Automatically adjusts to different screen sizes and text scaling
  • โšก Smart Debouncing: Prevents multiple toasts from showing simultaneously
  • ๐ŸŽช Auto-dismiss: Configurable duration with smooth fade-out animations
  • ๐ŸŽจ Text Customization: Custom fonts, colors, weights, and styles
  • ๐Ÿ‘๏ธ Icon Control: Show or hide icons with ease
  • ๐Ÿ›ก๏ธ Production-ready: Comprehensive error handling prevents crashes
  • ๐Ÿงช Well-tested: Extensive test coverage for all functionality
  • ๐Ÿ”„ Platform-adaptive: Works seamlessly across iOS, Android, Web, and Desktop

๐Ÿ“ฆ Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  modern_toast: ^0.0.5

Then run:

flutter pub get

๐Ÿš€ Quick Start #

Import the package:

import 'package:modern_toast/modern_toast.dart';

Basic Usage #

// Display predefined toast types
showModernToast(
  context,
  message: 'Operation completed successfully!',
  type: ModernToastType.success,
);

// Display custom toast (when type is null, use color and icon)
showModernToast(
  context,
  message: 'Custom styled toast!',
  color: Colors.purple,
  icon: Icons.star,
);

๐Ÿ“ Custom Sizing & Styling #

// Custom text styling
showModernToast(
  context,
  message: 'Custom styled message!',
  type: ModernToastType.success,
  textStyle: const TextStyle(
    fontSize: 16,
    fontWeight: FontWeight.bold,
    color: Colors.white,
    fontStyle: FontStyle.italic,
  ),
)

// Hide icon
showModernToast(
  context,
  message: 'Toast without icon',
  type: ModernToastType.info,
  showIcon: false,
)

๐ŸŽจ Custom Toast Examples #

// Fully customized toast
showModernToast(
  context,
  message: 'Beautiful custom toast',
  color: Colors.purple,
  icon: Icons.star,
  durationInMilliseconds: 4000,
  textStyle: const TextStyle(
    fontSize: 14,
    fontWeight: FontWeight.w600,
    color: Colors.white,
  ),
)

// Custom toast without icon
showModernToast(
  context,
  message: 'No icon toast',
  color: Colors.orange,
  showIcon: false,
  textStyle: const TextStyle(
    fontSize: 14,
    fontWeight: FontWeight.w600,
    color: Colors.white,
  ),
)

// Custom border radius
showModernToast(
  context,
  message: 'Rounded corners toast',
  type: ModernToastType.success,
  borderRadius: 8.0,
)

๐Ÿ“ Duration Control #

// Long duration toast
showModernToast(
  context,
  message: 'This toast stays for 5 seconds!',
  type: ModernToastType.success,
  durationInMilliseconds: 5000,
)

๐Ÿ“ Long Message Handling #

// Automatically handles long messages
showModernToast(
  context,
  message: 'This is a very long message that demonstrates how the toast handles multiple lines of text. The container will automatically adjust its width and the text will wrap properly with ellipsis overflow.',
  type: ModernToastType.info,
  durationInMilliseconds: 5000,
)

๐Ÿ“š Complete Example #

Here's a comprehensive example showcasing all major features:

import 'package:flutter/material.dart';
import 'package:modern_toast/modern_toast.dart';

class ToastDemoPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Modern Toast Demo')),
      body: SingleChildScrollView(
        padding: EdgeInsets.all(16),
        child: Column(
          children: [
            // Predefined toast types
            ElevatedButton(
              onPressed: () => showModernToast(
                context,
                message: 'Success! Operation completed.',
                type: ModernToastType.success,
              ),
              child: Text('Show Success Toast'),
            ),

            SizedBox(height: 12),

            ElevatedButton(
              onPressed: () => showModernToast(
                context,
                message: 'Error! Something went wrong.',
                type: ModernToastType.error,
              ),
              child: Text('Show Error Toast'),
            ),

            SizedBox(height: 12),

            ElevatedButton(
              onPressed: () => showModernToast(
                context,
                message: 'Warning! Check your input.',
                type: ModernToastType.warning,
              ),
              child: Text('Show Warning Toast'),
            ),

            SizedBox(height: 12),

            ElevatedButton(
              onPressed: () => showModernToast(
                context,
                message: 'Info: This is a message.',
                type: ModernToastType.info,
              ),
              child: Text('Show Info Toast'),
            ),

            SizedBox(height: 20),
            Divider(),

            // Custom toasts
            ElevatedButton(
              onPressed: () => showModernToast(
                context,
                message: 'Custom purple toast! โญ',
                color: Colors.purple,
                icon: Icons.star,
                durationInMilliseconds: 4000,
              ),
              child: Text('Custom Toast'),
            ),

            SizedBox(height: 12),

            ElevatedButton(
              onPressed: () => showModernToast(
                context,
                message: 'Bold custom text style!',
                type: ModernToastType.success,
                textStyle: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  color: Colors.white,
                ),
              ),
              child: Text('Custom Text Style'),
            ),

            SizedBox(height: 12),

            ElevatedButton(
              onPressed: () => showModernToast(
                context,
                message: 'No icon toast',
                type: ModernToastType.info,
                showIcon: false,
              ),
              child: Text('No Icon Toast'),
            ),

            SizedBox(height: 12),

            ElevatedButton(
              onPressed: () => showModernToast(
                context,
                message: 'Long duration toast (5s)',
                type: ModernToastType.success,
                durationInMilliseconds: 5000,
              ),
              child: Text('Long Duration'),
            ),
          ],
        ),
      ),
    );
  }
}

๐ŸŽฎ Interactive Example App #

The package includes a comprehensive example app that demonstrates all features:

  • 4 Predefined Toast Types: Success, Error, Warning, and Info
  • Custom Toast Examples: Purple and pink themed toasts
  • Text Customization: Bold, italic, and custom font sizes
  • Icon Control: Show/hide icon functionality
  • Duration Control: Short and long duration examples
  • Long Message Handling: Multi-line text with proper wrapping

To run the example app:

cd example
flutter run

The example app showcases all supported platforms:

  • Mobile (iOS/Android): Native platform experience
  • Desktop (macOS/Windows/Linux): Native desktop experience
  • Web: Browser-based experience

๐Ÿ“– API Reference #

showModernToast #

Displays a toast notification with predefined styling.

void showModernToast(
  BuildContext context, {
  required String message,
  ModernToastType? type,
  Color? color,
  IconData? icon,
  int? durationInMilliseconds,
  TextStyle? textStyle,
  bool showIcon = true,
  double borderRadius = 25.0,
  String? actionLabel,
  VoidCallback? onActionPressed,
})

Parameters:

  • context (required): BuildContext - The current widget context
  • message (required): String - The message to display
  • type: ModernToastType? - The toast type (success, error, warning, info). If null, custom color/icon must be provided
  • color: Color? - Custom background color (used when type is null)
  • icon: IconData? - Custom icon to display (used when type is null)
  • durationInMilliseconds: int? - Display duration in milliseconds (default: 3000)
  • textStyle: TextStyle? - Custom text styling
  • showIcon: bool - Whether to show the icon (default: true)
  • borderRadius: double - Border radius for the toast container (default: 25.0)
  • actionLabel: String? - Action button label (not yet implemented)
  • onActionPressed: VoidCallback? - Action button callback (not yet implemented)

ModernToastType Enum #

enum ModernToastType { success, error, warning, info }

ModernToastColors Class #

class ModernToastColors {
  static const Color success = Color(0xFF4CAF50);
  static const Color error = Color(0xFFF44336);
  static const Color warning = Color(0xFFFF9800);
  static const Color info = Color(0xFF2196F3);
  static const Color white = Color(0xFFFFFFFF);
}

๐ŸŽฏ Toast Types & Colors #

Type Color Icon Use Case
ModernToastType.success Green (#4CAF50) โœ… Check Circle Success messages
ModernToastType.error Red (#F44336) โŒ Error Error messages
ModernToastType.warning Orange (#FF9800) โš ๏ธ Warning Warning messages
ModernToastType.info Blue (#2196F3) โ„น๏ธ Info Informational messages

๐Ÿ”ง Platform Support #

Platform Status Notes
iOS โœ… Full Support Native iOS experience
Android โœ… Full Support Material Design experience
Web โœ… Full Support Browser-compatible
macOS โœ… Full Support Native macOS experience
Windows โœ… Full Support Native Windows experience
Linux โœ… Full Support Native Linux experience

๐Ÿ”— Dependencies #

This package uses these well-maintained dependencies:

  • animate_do ^3.3.4 - Smooth animations and transitions

๐Ÿงช Testing #

The package includes comprehensive tests covering:

  • โœ… Toast display functionality for all types
  • โœ… Custom styling options (colors, text styles, icons)
  • โœ… Animation behavior and timing
  • โœ… Platform compatibility across all supported platforms
  • โœ… Error handling and edge cases
  • โœ… Debouncing mechanism to prevent multiple toasts
  • โœ… Duration control and auto-dismiss functionality

Run tests with:

flutter test

๐Ÿค Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

For major changes, please open an issue first to discuss what you would like to change.

๐Ÿ“„ License #

MIT License - see the LICENSE file for details.

5
likes
160
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

A beautiful, modern, and customizable toast notification package for Flutter with smooth animations and multiple toast types.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

animate_do, flutter

More

Packages that depend on modern_toast