toastr_flutter 1.0.0
toastr_flutter: ^1.0.0 copied to clipboard
A highly customizable Flutter package for displaying beautiful toast notifications with animations, multiple types, and flexible positioning.
Toastr Flutter ๐ #
A highly customizable Flutter package for displaying beautiful toast notifications with smooth animations, multiple types, and flexible positioning.
Features โจ #
- ๐จ Multiple notification types: Success, Error, Warning, Info
- ๐ Flexible positioning: Top, Bottom, Center
- ๐ญ Smooth animations: Fade and slide animations
- ๐ฏ Highly customizable: Colors, icons, duration, and more
- ๐ Interactive: Tap to dismiss functionality
- ๐งช Well tested: Comprehensive test coverage
- ๐ฑ Responsive: Works on all screen sizes
- ๐ Easy to use: Simple API with helper methods
Installation ๐ฆ #
Add this to your package's pubspec.yaml
file:
dependencies:
toastr_flutter: ^1.0.0
Then run:
flutter pub get
Quick Start ๐ #
1. Initialize the service #
In your main app widget, initialize the toastr service with the overlay state:
import 'package:flutter/material.dart';
import 'package:toastr_flutter/toastr.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
// Initialize the toastr service
ToastrService.instance.initialize(Overlay.of(context));
}
@override
Widget build(BuildContext context) {
return Scaffold(
// Your app content
);
}
}
2. Show notifications #
Use the helper methods to show different types of notifications:
// Success notification
ToastrHelper.success('Operation completed successfully!');
// Error notification
ToastrHelper.error('Something went wrong!');
// Warning notification
ToastrHelper.warning('Please check your input');
// Info notification
ToastrHelper.info('Here is some useful information');
Advanced Usage ๐ง #
Custom Configuration #
For more control over the appearance and behavior:
ToastrHelper.custom(
ToastrConfig(
type: ToastrType.success,
message: 'Custom styled notification',
title: 'Custom Title',
duration: Duration(seconds: 5),
position: ToastrPosition.bottom,
backgroundColor: Colors.purple,
textColor: Colors.white,
customIcon: Icon(Icons.star, color: Colors.yellow),
dismissible: true,
animationDuration: Duration(milliseconds: 500),
),
);
Positioning #
Choose where your notifications appear:
// Top of the screen (default)
ToastrHelper.success('Message', position: ToastrPosition.top);
// Bottom of the screen
ToastrHelper.error('Message', position: ToastrPosition.bottom);
// Center of the screen
ToastrHelper.info('Message', position: ToastrPosition.center);
Managing Notifications #
// Clear all active notifications
ToastrHelper.clearAll();
// Check how many notifications are currently active
int count = ToastrService.instance.activeCount;
API Reference ๐ #
ToastrHelper #
Static helper class with convenient methods:
Method | Description |
---|---|
success(message, {title, duration, position}) |
Show success notification |
error(message, {title, duration, position}) |
Show error notification |
warning(message, {title, duration, position}) |
Show warning notification |
info(message, {title, duration, position}) |
Show info notification |
custom(ToastrConfig) |
Show notification with custom configuration |
clearAll() |
Clear all active notifications |
ToastrConfig #
Configuration class for customizing notifications:
Property | Type | Default | Description |
---|---|---|---|
type |
ToastrType |
required | Type of notification |
message |
String |
required | Message to display |
title |
String? |
null | Optional title |
duration |
Duration |
3 seconds | How long to show |
position |
ToastrPosition |
top | Where to show |
dismissible |
bool |
true | Can be dismissed by tap |
backgroundColor |
Color? |
null | Custom background color |
textColor |
Color? |
null | Custom text color |
customIcon |
Widget? |
null | Custom icon widget |
animationDuration |
Duration |
300ms | Animation duration |
ToastrType #
Available notification types:
ToastrType.success
- Green background with checkmarkToastrType.error
- Red background with X markToastrType.warning
- Orange background with warning iconToastrType.info
- Blue background with info icon
ToastrPosition #
Available positions:
ToastrPosition.top
- Top of the screenToastrPosition.bottom
- Bottom of the screenToastrPosition.center
- Center of the screen
Example ๐ก #
Check out the example directory for a complete working example that demonstrates all features of the package.
To run the example:
cd example
flutter run
Testing ๐งช #
The package includes comprehensive tests. Run them 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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License ๐ #
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog ๐ #
See CHANGELOG.md for a list of changes in each version.
Support ๐ฌ #
If you have any questions or need help, please:
- Check the documentation
- Look at the example
- Open an issue
Made with โค๏ธ by Ignacio Manchu(https://github.com/IgnacioMan1998)