flexible_toast 0.0.1 copy "flexible_toast: ^0.0.1" to clipboard
flexible_toast: ^0.0.1 copied to clipboard

A customizable Flutter notification library to display temporary messages.

flexible_toast

Pub Version License: MIT Stars

A highly customizable, transient notification system for Flutter, similar to Android's "Toast" or a simplified "Snackbar." Display beautiful, adaptable notifications at the top, center, or bottom of your screen that disappear automatically or can be dismissed by the user.


✨ Features

  • Flexible Positioning: Display notifications at the top, center, or bottom of the screen.
  • Customizable Content: Use simple strings for title and message, or provide custom widgets for full control.
  • Notification Types: Built-in support for success, warning, and error types with default styling.
  • Custom Icons & Colors: Override default icons and background/text colors for each notification type or provide a general background color.
  • Dismissible: Notifications can be dismissed by swiping or tapping a custom close icon.
  • Auto-Dismiss: Configurable duration for automatic dismissal.
  • Adaptive Height/Width: Notifications adapt to their content by default, with options for fixed dimensions.
  • Callbacks: Execute a VoidCallback when the notification is dismissed.
  • Single Instance: Ensures only one CNotify instance is active at a time to prevent UI clutter.

📸 Screenshots & Demos

Showcase the flexible_toast in action! Replace these placeholders with actual images, GIFs, or short MP4s to demonstrate your notifications.

Top Notification Example


A brief description of what this demo shows (e.g., "A success notification appearing at the top").

Center Notification Example


A brief description of what this demo shows (e.g., "A warning notification fading in at the center").

Bottom Notification Example


A brief description of what this demo shows (e.g., "An error notification sliding up from the bottom").

Custom Notification Example


A brief description of what this demo shows (e.g., "A fully customized notification with a unique icon and colors." ).


🚀 Getting Started

1. Add to your pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  flexible_toast: ^latest_version # Use the latest version from pub.dev

Then, run flutter pub get in your project's root directory.

2. Import it

import 'package:flexible_toast/flexible_toast.dart';
import 'package:flutter/material.dart'; // Make sure you import material.dart

💡 Usage Examples

The CNotify.show static method is all you need!

Basic Success Notification (Top)

ElevatedButton(
  onPressed: () {
    CNotify.show(
      context: context,
      title: 'Success!',
      message: 'Your operation was completed successfully.',
      type: NotifyType.success,
      position: NotifyPosition.top,
      duration: 3000, // 3 seconds
    );
  },
  child: const Text('Show Success (Top)'),
),

Warning Notification (Center)

ElevatedButton(
  onPressed: () {
    CNotify.show(
      context: context,
      title: 'Heads Up!',
      message: 'Something needs your attention. Please review.',
      type: NotifyType.warning,
      position: NotifyPosition.center,
      duration: 5000, // 5 seconds
    );
  },
  child: const Text('Show Warning (Center)'),
),

Error Notification (Bottom)

ElevatedButton(
  onPressed: () {
    CNotify.show(
      context: context,
      title: 'Error Occurred!',
      message: 'Failed to save data. Please try again.',
      type: NotifyType.error,
      position: NotifyPosition.bottom,
      dismissDirection: DismissDirection.horizontal, // Can dismiss left/right
      closeCallBack: () {
        print('Error notification was dismissed!');
      },
    );
  },
  child: const Text('Show Error (Bottom)'),
),


🎨 Customization

flexible_toast offers extensive customization options.

Custom Icons and Colors

ElevatedButton(
  onPressed: () {
    CNotify.show(
      context: context,
      title: 'Custom Alert!',
      message: 'This is a notification with a custom look.',
      type: NotifyType.warning, // Can still use a type for defaults not overridden
      position: NotifyPosition.top,
      backgroundColor: Colors.deepPurple, // Overrides type-specific color
      successIcon: const Icon(Icons.star_rounded, color: Colors.amberAccent), // Custom icon for success
      titleColor: Colors.amberAccent,
      messageColor: Colors.white70,
      closeIcon: const Icon(Icons.close, color: Colors.white),
      elevation: 8.0,
      padding: const EdgeInsets.all(20.0), // More padding
    );
  },
  child: const Text('Show Custom Notification'),
),

Using Widgets for Title and Message

You can provide any Widget for the title and message, giving you ultimate control over their appearance.

ElevatedButton(
  onPressed: () {
    CNotify.show(
      context: context,
      titleWidget: Row(
        children: [
          Icon(Icons.thumb_up, color: Colors.lightGreenAccent),
          SizedBox(width: 8),
          Text(
            'Operation Complete!',
            style: TextStyle(
              color: Colors.lightGreenAccent,
              fontWeight: FontWeight.bold,
              fontSize: 16,
            ),
          ),
        ],
      ),
      messageWidget: Text(
        'All files have been successfully synchronized to the cloud.',
        style: TextStyle(color: Colors.white, fontSize: 13),
      ),
      backgroundColor: Colors.green.shade800,
      position: NotifyPosition.top,
      duration: 4000,
    );
  },
  child: const Text('Show Widget-Based Notification'),
),

Fixed Height and Width

ElevatedButton(
  onPressed: () {
    CNotify.show(
      context: context,
      title: 'Fixed Size',
      message: 'This notification has a predefined height and width.',
      type: NotifyType.warning, // Assuming you add an warning type or use default
      backgroundColor: Colors.blueGrey,
      height: 80.0,
      width: 300.0,
      position: NotifyPosition.center,
    );
  },
  child: const Text('Show Fixed Size Notification'),
),


🤝 Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.


📄 License

This package is released under the MIT License. See LICENSE file for more details.


👨‍💻 Author

emrhnzngn


2
likes
0
points
14
downloads

Publisher

verified publisherdevastral.tr

Weekly Downloads

A customizable Flutter notification library to display temporary messages.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flexible_toast