cherry_toast_msgs 1.3.0
cherry_toast_msgs: ^1.3.0 copied to clipboard
A beautiful, responsive toast notification package for Flutter with animated overlays, customizable themes, builder pattern API, queue management, and advanced interactive features.
Cherry Toast Messages #
A beautiful, responsive toast notification package for Flutter with animated overlays, customizable themes, and advanced features. Perfect for displaying success, error, warning, and info messages with smooth animations and enhanced user experience.
โจ Features #
- ๐จ Beautiful Design: Modern, clean toast notifications with smooth animations
- ๐ฑ Responsive: Automatically adapts to different screen sizes and orientations
- ๐ญ Multiple Themes: Pre-built themes for success, error, warning, and info messages with dark mode support
- โก Customizable: Fully customizable colors, styles, animations, and behaviors
- ๐ Easy to Use: Simple API with intuitive method names and fluent builder pattern
- ๐ฏ Accessible: Proper contrast ratios, touch targets, and screen reader support
- ๐ Queue Management: Smart queue system to handle multiple toasts gracefully
- ๐ Interactive: Swipe-to-dismiss, tap-to-dismiss, and action button support
- ๐ช Advanced Animations: Multiple animation types (slide, fade, scale, bounce)
- ๐ Flexible Positioning: Top, bottom, center, and custom positioning
- ๐๏ธ Builder Pattern: Fluent API for complex toast configurations
- ๐ง Enhanced Error Handling: Robust validation and error recovery
- ๐ Lifecycle Callbacks: Complete control over toast lifecycle events
๐ Getting Started #
Installation #
Add this to your package's pubspec.yaml
file:
dependencies:
cherry_toast_msgs: ^1.3.0
Import #
import 'package:cherry_toast_msgs/cherry_toast_msgs.dart';
๐ Usage #
Basic Toast Types #
Success Toast
CherryToastMsgs.showSuccessToast(
context: context,
title: "Success!",
description: "Your action was completed successfully.",
);
Error Toast
CherryToastMsgs.showErrorToast(
context,
"Error!",
"Something went wrong. Please try again.",
);
Warning Toast
CherryToastMsgs.showWarningToast(
context,
"Warning!",
"Please check your input before proceeding.",
);
Info Toast
CherryToastMsgs.showInfoToast(
context,
"Information",
"Here's some useful information for you.",
);
๐๏ธ Builder Pattern (New!) #
The fluent builder pattern provides a more flexible and readable way to create toasts:
// Simple builder usage
CherryToastMsgs.builder()
.context(context)
.title("Builder Pattern")
.description("This toast was created using the fluent builder API")
.success()
.show();
// Advanced builder usage
CherryToastMsgs.builder()
.context(context)
.title("Advanced Toast")
.description("With multiple features enabled")
.error()
.darkMode()
.hapticFeedback()
.duration(Duration(seconds: 5))
.position(ToastPosition.center)
.actions([
TextButton(
onPressed: () => print('Action pressed'),
child: Text('Action'),
),
])
.callbacks(ToastCallbacks(
onShow: () => print('Toast shown'),
onDismiss: () => print('Toast dismissed'),
))
.show();
๐จ Theme System (New!) #
Predefined Themes
// Light themes
CherryToastMsgs.builder()
.context(context)
.title("Themed Toast")
.description("Using predefined theme")
.theme(CherryToastTheme.success)
.show();
// Dark themes
CherryToastMsgs.builder()
.context(context)
.title("Dark Theme")
.description("Using dark theme variant")
.theme(CherryToastTheme.successDark)
.show();
// Or use the convenience method
CherryToastMsgs.builder()
.context(context)
.title("Auto Dark Theme")
.description("Automatically uses dark variant")
.success()
.darkMode()
.show();
Custom Themes
final customTheme = CherryToastTheme.success.copyWith(
backgroundColor: Colors.purple.shade50,
borderColor: Colors.purple.shade200,
iconBackground: Colors.purple,
);
CherryToastMsgs.builder()
.context(context)
.title("Custom Theme")
.description("Using custom theme colors")
.theme(customTheme)
.show();
๐ช Animation Types (New!) #
// Slide animation (default)
CherryToastMsgs.builder()
.context(context)
.title("Slide Animation")
.description("Slides in from the edge")
.success()
.animation(CherryToastAnimation.slide)
.show();
// Fade animation
CherryToastMsgs.builder()
.context(context)
.title("Fade Animation")
.description("Fades in smoothly")
.info()
.animation(CherryToastAnimation.fade)
.show();
// Scale animation
CherryToastMsgs.builder()
.context(context)
.title("Scale Animation")
.description("Scales up from center")
.warning()
.animation(CherryToastAnimation.scale)
.show();
// Bounce animation
CherryToastMsgs.builder()
.context(context)
.title("Bounce Animation")
.description("Bounces in with elastic effect")
.error()
.animation(CherryToastAnimation.bounce)
.show();
๐ Positioning #
// Top position (default)
CherryToastMsgs.showSuccessToast(
context: context,
title: "Top Toast",
description: "Appears at the top",
position: ToastPosition.top,
);
// Bottom position
CherryToastMsgs.showErrorToast(
context,
"Bottom Toast",
"Appears at the bottom",
position: ToastPosition.bottom,
);
// Center position
CherryToastMsgs.showInfoToast(
context,
"Center Toast",
"Appears in the center",
position: ToastPosition.center,
);
// Custom position with offset
CherryToastMsgs.showWarningToast(
context,
"Custom Position",
"Custom offset from top",
position: ToastPosition.custom,
topOffset: 100.0,
);
๐๏ธ Configuration Options (New!) #
// Quick configurations
CherryToastMsgs.builder()
.context(context)
.title("Quick Toast")
.description("Short duration, fast animation")
.success()
.quick() // 2 seconds, fast animation
.show();
CherryToastMsgs.builder()
.context(context)
.title("Persistent Toast")
.description("Longer duration, always shows close button")
.warning()
.persistent() // 8 seconds, always closeable
.show();
// Custom configuration
final customConfig = CherryToastConfig(
duration: Duration(seconds: 5),
animationType: CherryToastAnimation.bounce,
enableHapticFeedback: true,
dismissOnTap: true,
showCloseButton: true,
);
CherryToastMsgs.showSuccessToast(
context: context,
title: "Custom Config",
description: "Using custom configuration",
config: customConfig,
);
๐ Interactive Features (New!) #
Action Buttons
CherryToastMsgs.builder()
.context(context)
.title("Interactive Toast")
.description("Toast with action buttons")
.warning()
.actions([
TextButton(
onPressed: () => print('Retry pressed'),
child: Text('Retry'),
),
TextButton(
onPressed: () => print('Cancel pressed'),
child: Text('Cancel'),
),
])
.show();
Lifecycle Callbacks
CherryToastMsgs.builder()
.context(context)
.title("Callback Toast")
.description("With lifecycle callbacks")
.info()
.callbacks(ToastCallbacks(
onShow: () => print('Toast appeared'),
onDismiss: () => print('Toast will disappear'),
onDismissed: (reason) => print('Toast dismissed: $reason'),
onTap: () => print('Toast was tapped'),
))
.show();
Haptic Feedback
CherryToastMsgs.builder()
.context(context)
.title("Haptic Toast")
.description("Provides haptic feedback")
.success()
.hapticFeedback()
.show();
๐ Queue Management (New!) #
// Multiple toasts are automatically queued
for (int i = 0; i < 5; i++) {
CherryToastMsgs.builder()
.context(context)
.title("Toast ${i + 1}")
.description("Queued toast message")
.info()
.show();
}
// Clear the queue
CherryToastMsgs.clearQueue();
// Check queue size
int queueSize = CherryToastMsgs.queueSize;
print('Current queue size: $queueSize');
๐ท๏ธ Static Info Container #
For static information displays, use the StaticInfoContainer
:
StaticInfoContainer(
message: "This is a static information container",
icon: Icons.info_outline,
backgroundColor: Colors.blue.shade50,
borderColor: Colors.blue.shade200,
iconColor: Colors.blue.shade600,
textColor: Colors.blue.shade700,
)
๐จ Custom Styling #
CherryToastMsgs.showAnimatedToast(
context: context,
title: "Custom Styled Toast",
description: "Fully customized appearance",
icon: Icons.star,
iconColor: Colors.white,
iconBackground: Colors.purple,
backgroundColor: Colors.purple.shade50,
borderColor: Colors.purple.shade200,
titleStyle: TextStyle(
color: Colors.purple.shade800,
fontWeight: FontWeight.bold,
fontSize: 18,
),
descriptionStyle: TextStyle(
color: Colors.purple.shade600,
fontSize: 16,
),
borderRadius: 16,
borderWidth: 2,
duration: Duration(seconds: 5),
elevation: 12,
width: 300,
height: 120,
animationType: CherryToastAnimation.bounce,
dismissOnTap: true,
showCloseButton: true,
);
๐ API Reference #
CherryToastMsgs #
Static Methods
showSuccessToast()
- Shows a green success toastshowErrorToast()
- Shows a red error toastshowWarningToast()
- Shows a yellow warning toastshowInfoToast()
- Shows a blue info toastshowAnimatedToast()
- Method for custom toasts with full customizationbuilder()
- Creates a new toast builder instancesuccess()
,error()
,warning()
,info()
- Quick builder methodsclearQueue()
- Clears all queued toastsqueueSize
- Gets current queue size
Enhanced Parameters
All toast methods now support:
config
- Toast configuration objectenableHapticFeedback
- Enable haptic feedbackcallbacks
- Lifecycle callbacks- Enhanced positioning and styling options
CherryToastBuilder (New!) #
Fluent API for building complex toasts:
Configuration Methods
context(BuildContext)
- Set build contexttitle(String)
- Set title textdescription(String)
- Set description texttheme(CherryToastTheme)
- Set predefined themeconfig(CherryToastConfig)
- Set configurationcallbacks(ToastCallbacks)
- Set lifecycle callbacks
Styling Methods
darkMode([bool])
- Enable/disable dark modewidth(double)
- Set custom widthheight(double)
- Set custom heightanimation(CherryToastAnimation)
- Set animation type
Positioning Methods
position(ToastPosition)
- Set positiontop([double])
- Position at top with optional offsetbottom([double])
- Position at bottom with optional offsetcenter()
- Position at centercustomPosition(double)
- Custom positioning with offset
Behavior Methods
duration(Duration)
- Set display durationhapticFeedback([bool])
- Enable haptic feedbackpersistent()
- Use persistent configurationquick()
- Use quick configuration
Content Methods
actions(List<Widget>)
- Add action buttonscustomContent(Widget)
- Set custom content widget
Quick Theme Methods
success()
- Apply success themeerror()
- Apply error themewarning()
- Apply warning themeinfo()
- Apply info theme
Build Method
show()
- Build and display the toast
CherryToastTheme (New!) #
Predefined theme system:
Light Themes
CherryToastTheme.success
- Green success themeCherryToastTheme.error
- Red error themeCherryToastTheme.warning
- Orange warning themeCherryToastTheme.info
- Blue info theme
Dark Themes
CherryToastTheme.successDark
- Dark success themeCherryToastTheme.errorDark
- Dark error themeCherryToastTheme.warningDark
- Dark warning themeCherryToastTheme.infoDark
- Dark info theme
Methods
getTheme(String, {bool isDark})
- Get theme by typecopyWith({...})
- Create custom theme variant
CherryToastConfig (New!) #
Configuration class for toast behavior:
Properties
duration
- Display duration (default: 3 seconds)animationType
- Animation type (default: slideAndFade)animationDuration
- Animation duration (default: 350ms)enableHapticFeedback
- Enable haptic feedback (default: false)enableSoundFeedback
- Enable sound feedback (default: false)dismissOnTap
- Dismiss on tap (default: true)showCloseButton
- Show close button (default: true)borderRadius
,borderWidth
,elevation
- Visual propertiesshadowColor
,padding
,margin
- Layout properties
Predefined Configurations
CherryToastConfig.defaultConfig
- Default settingsCherryToastConfig.quick
- Quick toast (2 seconds, fast animation)CherryToastConfig.persistent
- Persistent toast (8 seconds, always closeable)
CherryToastAnimation (New!) #
Animation types:
CherryToastAnimation.slide
- Slide from edgeCherryToastAnimation.fade
- Fade in/outCherryToastAnimation.scale
- Scale from centerCherryToastAnimation.bounce
- Bounce with elastic effectCherryToastAnimation.slideAndFade
- Combined slide and fade (default)
ToastCallbacks (New!) #
Lifecycle callback functions:
onShow
- Called when toast appearsonDismiss
- Called when toast starts dismissingonDismissed(ToastDismissReason)
- Called when toast is fully dismissedonTap
- Called when toast is tapped
ToastDismissReason (New!) #
Dismissal reasons:
ToastDismissReason.timeout
- Auto-dismissed after durationToastDismissReason.userDismiss
- User clicked close buttonToastDismissReason.swipe
- User swiped to dismissToastDismissReason.tap
- User tapped to dismissToastDismissReason.programmatic
- Dismissed programmatically
ToastPosition #
Position options:
ToastPosition.top
- Top of screen (default)ToastPosition.bottom
- Bottom of screenToastPosition.center
- Center of screenToastPosition.custom
- Custom position with offset
StaticInfoContainer #
Static information display widget:
Properties
message
- Text message to displayicon
- Icon to display (default: Icons.info_outline)backgroundColor
,borderColor
,iconColor
,textColor
- ColorsborderRadius
,padding
,iconSize
,fontSize
- Stylingwidth
,height
- Custom dimensions
๐ง Migration Guide #
From v1.2.x to v1.3.x #
Breaking Changes
StaticeInfoContainer
renamed toStaticInfoContainer
New Features
- Builder pattern API
- Theme system with dark mode support
- Enhanced animation types
- Queue management system
- Lifecycle callbacks
- Haptic feedback support
- Action buttons
- Enhanced error handling
Migration Steps
- Update widget name:
// Old
StaticeInfoContainer(message: "Info")
// New
StaticInfoContainer(message: "Info")
- Consider using builder pattern for complex toasts:
// Old
CherryToastMsgs.showAnimatedToast(
context: context,
title: "Title",
description: "Description",
icon: Icons.success,
// ... many parameters
);
// New (recommended)
CherryToastMsgs.builder()
.context(context)
.title("Title")
.description("Description")
.success()
.show();
- Use new theme system:
// New theme-based approach
CherryToastMsgs.builder()
.context(context)
.title("Themed Toast")
.description("Using predefined theme")
.success()
.darkMode() // Automatically uses dark variant
.show();
๐งช Testing #
The package includes comprehensive tests for all components:
flutter test
Test coverage includes:
- Widget creation and rendering
- Theme system functionality
- Configuration validation
- Queue management
- Animation systems
- Error handling
๐ค 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.
Development Setup #
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
flutter test
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ License #
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Support #
If you find this package helpful, please consider:
- โญ Starring the repository
- ๐ Reporting bugs and issues
- ๐ก Suggesting new features
- ๐ Improving documentation
- ๐ Sharing with the community
๐ Contact #
- GitHub: Abdullah-T3/cherry_toast_msgs
- Issues: Report Issues
- Discussions: GitHub Discussions
Made with โค๏ธ by Abdullah Ahmed