Toastification: A Comprehensive Guide to Toast Notifications in Flutter

Published on by Flutter News Hub

Toastification: A Comprehensive Guide to Toast Notifications in Flutter

Toast notifications are an integral part of delivering timely and informative feedback to users in mobile applications. Toastification is a powerful Flutter package that simplifies the creation and management of toast notifications, empowering developers to enhance the user experience of their apps.

Key Features

  • Seamless integration with Flutter apps
  • Predefined and customizable toast styles
  • Queue management for multiple notifications
  • Extensive customization options for appearance and behavior
  • Global configuration for consistent behavior across the app

Usage Guide

Basic Usage

  1. Import the Toastification package:
import 'package:toastification/toastification.dart';
  1. Use the toastification.show() method to display predefined toast messages:
toastification.show(
  context: context,
  title: Text('Hello, world!'),
  autoCloseDuration: Duration(seconds: 5),
);

Custom Toast Messages

For complete control over the appearance and behavior, use toastification.showCustom():

toastification.showCustom(
  context: context,
  autoCloseDuration: Duration(seconds: 5),
  builder: (context, holder) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(8),
        color: Colors.blue,
      ),
      padding: EdgeInsets.all(16),
      margin: EdgeInsets.all(8),
      child: Column(
        // ... Your custom toast content here
      ),
    );
  },
);

Advanced Options

  • Toast Types: Use ToastificationType enum to choose between predefined toast types (success, error, info, warning).
  • Toast Styles: Customize the appearance with ToastificationStyle enum (flat, minimal, rounded, gradient).
  • Custom Animations: Control the toast's animation using animationDuration and animationBuilder.
  • Global Configuration: Set default behavior for all toasts using ToastificationConfigProvider.

Notification Management

  • Finding a Notification:
final notification = toastification.findToastificationItem('my_notification_id');
  • Dismissing a Notification:
toastification.dismiss(notification);
  • Dismissing a Notification by ID:
toastification.dismissById('my_notification_id');

Design & Contributions

Toastification's design is crafted by Sepide Moqadasi. Contributions are welcome; please refer to the CONTRIBUTING.md file.

License

Toastification is licensed under BSD-3-Clause License.

Flutter News Hub