toastr_flutter 1.0.0 copy "toastr_flutter: ^1.0.0" to clipboard
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.

pub package License: MIT

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 checkmark
  • ToastrType.error - Red background with X mark
  • ToastrType.warning - Orange background with warning icon
  • ToastrType.info - Blue background with info icon

ToastrPosition #

Available positions:

  • ToastrPosition.top - Top of the screen
  • ToastrPosition.bottom - Bottom of the screen
  • ToastrPosition.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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. 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:

  1. Check the documentation
  2. Look at the example
  3. Open an issue

Made with โค๏ธ by Ignacio Manchu(https://github.com/IgnacioMan1998)

0
likes
0
points
38
downloads

Publisher

verified publisherignacio-manchu.com

Weekly Downloads

A highly customizable Flutter package for displaying beautiful toast notifications with animations, multiple types, and flexible positioning.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

flutter

More

Packages that depend on toastr_flutter