### Install Toastification Dependency Source: https://context7.com/payam-zahedi/toastification/llms.txt Add the package to your pubspec.yaml file and fetch the dependencies. ```yaml dependencies: toastification: ^3.2.0 ``` ```bash flutter pub get ``` -------------------------------- ### Demonstrate Queue Management Source: https://context7.com/payam-zahedi/toastification/llms.txt This example demonstrates queue management by first dismissing all existing toasts, then creating three new ones, and finally attempting to dismiss the first in the queue. Note: `dismissFirst`/`dismissLast` are internal methods; use `findToastificationItem` for granular control. ```dart ElevatedButton( onPressed: () { toastification.dismissAll(delayForAnimation: false); // Recreate some toasts for (int i = 1; i <= 3; i++) { toastification.show( context: context, title: Text('Toast $i'), autoCloseDuration: const Duration(seconds: 30), ); } // Then dismiss first Future.delayed(const Duration(milliseconds: 500), () { // Note: dismissFirst/dismissLast are internal manager methods // Use dismiss with findToastificationItem for granular control }); }, child: const Text('Demo Queue Management'), ) ``` -------------------------------- ### Configure Global and Page-Specific Toast Settings Source: https://context7.com/payam-zahedi/toastification/llms.txt Examples of applying app-wide toast configurations using ToastificationConfigProvider and overriding them for specific pages. ```dart import 'package:flutter/material.dart'; import 'package:toastification/toastification.dart'; // App-wide configuration using MaterialApp builder class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return ToastificationWrapper( child: MaterialApp( title: 'Toastification Demo', builder: (context, child) { return ToastificationConfigProvider( config: ToastificationConfig( alignment: Alignment.topCenter, itemWidth: 450, animationDuration: const Duration(milliseconds: 500), maxToastLimit: 5, maxTitleLines: 2, maxDescriptionLines: 4, blockBackgroundInteraction: false, marginBuilder: (context, alignment) { return const EdgeInsets.symmetric(horizontal: 16, vertical: 24); }, animationBuilder: (context, animation, alignment, child) { return FadeTransition( opacity: animation, child: SlideTransition( position: Tween( begin: const Offset(0, -0.5), end: Offset.zero, ).animate(CurvedAnimation( parent: animation, curve: Curves.easeOutBack, )), child: child, ), ); }, ), child: child!, ); }, home: const HomePage(), ), ); } } // Page-specific configuration class CheckoutPage extends StatelessWidget { const CheckoutPage({super.key}); @override Widget build(BuildContext context) { return ToastificationConfigProvider( config: const ToastificationConfig( alignment: Alignment.bottomCenter, itemWidth: 380, blockBackgroundInteraction: true, // Block clicks during checkout toasts maxToastLimit: 3, ), child: Scaffold( appBar: AppBar(title: const Text('Checkout')), body: Center( child: ElevatedButton( onPressed: () { toastification.show( context: context, title: const Text('Processing payment...'), type: ToastificationType.info, autoCloseDuration: const Duration(seconds: 3), ); }, child: const Text('Place Order'), ), ), ), ); } } ``` -------------------------------- ### Show Custom Toast with Interactive Elements Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Use showCustom() to build highly customized toast messages. This example demonstrates a toast with a dismiss button and interactive hold/release behavior for the auto-close timer. Requires ToastificationWrapper or a valid BuildContext. ```dart toastification.showCustom( context: context, // optional if you use ToastificationWrapper autoCloseDuration: const Duration(seconds: 5), alignment: Alignment.topRight, dismissDirection: DismissDirection.none, animationBuilder: (context, animation, alignment, child) { // Fade animation for the toast return FadeTransition(opacity: animation, child: child); }, builder: (context, holder) { return Container( margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), padding: const EdgeInsets.all(3), decoration: BoxDecoration( color: Colors.white.withAlpha(200), borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.green.withAlpha(100), blurRadius: 40, spreadRadius: 15, ), ], ), child: GestureDetector( onTapDown: (_) => holder.pause(), // Pause dismiss timer on hold onTapUp: (_) => holder.start(), // Resume dismiss timer on release dragStartBehavior: DragStartBehavior.down, child: DecoratedBox( decoration: const BoxDecoration( color: Colors.green, borderRadius: BorderRadius.only( topLeft: Radius.circular(10), topRight: Radius.circular(10), bottomLeft: Radius.circular(10), bottomRight: Radius.circular(50), ), ), child: Padding( padding: const EdgeInsets.symmetric( horizontal: 16, vertical: 12, ), child: Row( children: [ const Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Title', style: TextStyle( color: Colors.white, fontWeight: FontWeight.w600, fontSize: 14, ), ), SizedBox(height: 4), Text( 'Custom Toast Message', style: TextStyle( color: Colors.white70, fontWeight: FontWeight.w400, fontSize: 12, ), ), ], ), ), IconButton( onPressed: () { // Dismiss the toast toastification.dismissById(holder.id); }, icon: const Icon( Icons.close_rounded, color: Colors.white, ), ), ], ), ), ), ), ); }, ); ``` -------------------------------- ### Add Toastification to pubspec.yaml Source: https://github.com/payam-zahedi/toastification/blob/main/README.md To use Toastification, add it to your pubspec.yaml file and run `flutter pub get`. ```yaml dependencies: toastification: latest_version ``` -------------------------------- ### Show Custom Toast Notification Type Source: https://context7.com/payam-zahedi/toastification/llms.txt Illustrates how to define and display a custom toast notification type with a unique name, color, and icon. This example uses a 'celebration' type with purple color and a celebration icon. ```dart const customType = ToastificationType.custom( 'celebration', Colors.purple, Icons.celebration, ); tostification.show( context: context, type: customType, style: ToastificationStyle.fillColored, title: const Text('Custom Celebration!'), description: const Text('You created a custom toast type!'), autoCloseDuration: const Duration(seconds: 5), ); ``` -------------------------------- ### Show Method - Basic Usage Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Demonstrates the basic usage of the `show` method to display a predefined toast message. ```APIDOC ## POST /toastification/show ### Description Displays a predefined toast message with a title. ### Method POST ### Endpoint /toastification/show ### Parameters #### Request Body - **context** (BuildContext) - Optional - The build context for displaying the toast. Optional if ToastificationWrapper is used. - **title** (Widget) - Required - The widget to display as the toast title (e.g., Text, RichText). - **autoCloseDuration** (Duration) - Optional - The duration after which the toast will automatically close. ### Request Example ```dart toastification.show( context: context, title: Text('Hello, world!'), autoCloseDuration: const Duration(seconds: 5), ); ``` ### Response #### Success Response (200) - **toastId** (String) - The unique identifier for the displayed toast. #### Response Example ```json { "toastId": "toast_12345" } ``` ``` -------------------------------- ### Show Method - Advanced Customization Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Illustrates advanced customization options for the `show` method, including type, style, alignment, icons, colors, and callbacks. ```APIDOC ## POST /toastification/show (Advanced) ### Description Displays a highly customized toast message with various styling and behavioral options. ### Method POST ### Endpoint /toastification/show ### Parameters #### Request Body - **context** (BuildContext) - Optional - The build context for displaying the toast. Optional if ToastificationWrapper is used. - **type** (ToastificationType) - Optional - The type of the toast (e.g., success, error, warning, info). - **style** (ToastificationStyle) - Optional - The visual style of the toast (e.g., flat, fillColored, flatColored, minimal, simple). - **autoCloseDuration** (Duration) - Optional - The duration after which the toast will automatically close. - **title** (Widget) - Required - The widget to display as the toast title. - **description** (Widget) - Optional - The widget to display as the toast description. - **alignment** (Alignment) - Optional - The alignment of the toast on the screen (e.g., Alignment.topRight). - **direction** (TextDirection) - Optional - The text direction for the toast content. - **animationDuration** (Duration) - Optional - The duration of the toast animation. - **animationBuilder** (Widget Function) - Optional - A custom animation builder for the toast. - **icon** (Icon) - Optional - A custom icon to display in the toast. - **showIcon** (bool) - Optional - Whether to show the icon. - **primaryColor** (Color) - Optional - The primary color of the toast. - **backgroundColor** (Color) - Optional - The background color of the toast. - **foregroundColor** (Color) - Optional - The foreground color of the toast. - **padding** (EdgeInsets) - Optional - Padding around the toast content. - **margin** (EdgeInsets) - Optional - Margin around the toast. - **borderRadius** (BorderRadius) - Optional - Border radius for the toast. - **boxShadow** (List) - Optional - Box shadow for the toast. - **showProgressBar** (bool) - Optional - Whether to show a progress bar. - **closeButton** (ToastCloseButton) - Optional - Configuration for the close button. - **closeOnClick** (bool) - Optional - Whether the toast can be closed by clicking on it. - **pauseOnHover** (bool) - Optional - Whether the toast pauses its auto-close timer on hover. - **dragToClose** (bool) - Optional - Whether the toast can be closed by dragging. - **applyBlurEffect** (bool) - Optional - Whether to apply a blur effect to the toast. - **onHoverMouseCursor** (MouseCursor) - Optional - The mouse cursor to display when hovering over the toast. - **callbacks** (ToastificationCallbacks) - Optional - Callback functions for toast events (onTap, onCloseButtonTap, onAutoCompleteCompleted, onDismissed). ### Request Example ```dart toastification.show( context: context, type: ToastificationType.success, style: ToastificationStyle.flat, autoCloseDuration: const Duration(seconds: 5), title: Text('Hello, World!'), description: RichText(text: const TextSpan(text: 'This is a sample toast message.')), alignment: Alignment.topRight, direction: TextDirection.ltr, animationDuration: const Duration(milliseconds: 300), animationBuilder: (context, animation, alignment, child) { return FadeTransition( turns: animation, child: child, ); }, icon: const Icon(Icons.check), showIcon: true, primaryColor: Colors.green, backgroundColor: Colors.white, foregroundColor: Colors.black, padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16), margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), borderRadius: BorderRadius.circular(12), boxShadow: const [ BoxShadow( color: Color(0x07000000), blurRadius: 16, offset: Offset(0, 16), spreadRadius: 0, ) ], showProgressBar: true, closeButton: ToastCloseButton( showType: CloseButtonShowType.onHover, buttonBuilder: (context, onClose) { return OutlinedButton.icon( onPressed: onClose, icon: const Icon(Icons.close, size: 20), label: const Text('Close'), ); }, ), closeOnClick: false, pauseOnHover: true, dragToClose: true, applyBlurEffect: true, onHoverMouseCursor: SystemMouseCursors.click, callbacks: ToastificationCallbacks( onTap: (toastItem) => print('Toast ${toastItem.id} tapped'), onCloseButtonTap: (toastItem) => print('Toast ${toastItem.id} close button tapped'), onAutoCompleteCompleted: (toastItem) => print('Toast ${toastItem.id} auto complete completed'), onDismissed: (toastItem) => print('Toast ${toastItem.id} dismissed'), ), ); ``` ### Response #### Success Response (200) - **toastId** (String) - The unique identifier for the displayed toast. #### Response Example ```json { "toastId": "toast_67890" } ``` ``` -------------------------------- ### toastification.showCustom() Source: https://context7.com/payam-zahedi/toastification/llms.txt Displays a custom toast widget using a builder function that provides access to the toast item's lifecycle controls. ```APIDOC ## toastification.showCustom() ### Description Displays a custom toast widget. The builder function receives the context and a ToastificationItem holder, which allows for manual control over the toast's timer (pause/start) and provides the unique item ID for dismissal. ### Parameters #### Request Body - **context** (BuildContext) - Required - The build context for the toast. - **autoCloseDuration** (Duration) - Optional - The duration after which the toast automatically closes. - **alignment** (Alignment) - Optional - The screen alignment for the toast. - **builder** (Function) - Required - A function that returns a Widget. Receives (context, holder). - **animationBuilder** (Function) - Optional - A function to define custom entry/exit animations. ### Request Example ```dart toastification.showCustom( context: context, autoCloseDuration: const Duration(seconds: 5), alignment: Alignment.bottomLeft, builder: (context, holder) { return Container(child: Text('Custom Toast')); } ) ``` ``` -------------------------------- ### Display Custom Toast Widgets with toastification Source: https://context7.com/payam-zahedi/toastification/llms.txt Demonstrates creating a custom toast with interactive elements, timer controls, and custom styling using showCustom(). ```dart import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:toastification/toastification.dart'; class CustomToastExamples extends StatelessWidget { const CustomToastExamples({super.key}); @override Widget build(BuildContext context) { return Column( children: [ // Custom styled notification with interactive elements ElevatedButton( onPressed: () { toastification.showCustom( context: context, autoCloseDuration: const Duration(seconds: 8), alignment: Alignment.bottomCenter, builder: (context, holder) { return Container( margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), padding: const EdgeInsets.all(4), decoration: BoxDecoration( gradient: LinearGradient( colors: [Colors.purple.shade400, Colors.blue.shade400], ), borderRadius: BorderRadius.circular(16), boxShadow: [ BoxShadow( color: Colors.purple.withOpacity(0.4), blurRadius: 20, spreadRadius: 2, ), ], ), child: GestureDetector( onTapDown: (_) => holder.pause(), // Pause timer on press onTapUp: (_) => holder.start(), // Resume timer on release dragStartBehavior: DragStartBehavior.down, child: Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12), ), child: Row( children: [ Container( padding: const EdgeInsets.all(8), decoration: BoxDecoration( color: Colors.purple.shade50, shape: BoxShape.circle, ), child: Icon(Icons.celebration, color: Colors.purple.shade400), ), const SizedBox(width: 12), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ const Text( 'Achievement Unlocked!', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 16, ), ), Text( 'You completed 100 tasks', style: TextStyle( color: Colors.grey.shade600, fontSize: 14, ), ), ], ), ), TextButton( onPressed: () { // Handle action toastification.dismissById(holder.id); }, child: const Text('View'), ), IconButton( onPressed: () => toastification.dismissById(holder.id), icon: const Icon(Icons.close, size: 20), ), ], ), ), ), ); }, ); }, child: const Text('Show Custom Achievement Toast'), ), // Undo action toast ElevatedButton( onPressed: () { toastification.showCustom( context: context, autoCloseDuration: const Duration(seconds: 5), alignment: Alignment.bottomLeft, animationBuilder: (context, animation, alignment, child) { return SlideTransition( position: Tween( ``` -------------------------------- ### Show Custom Toast Using GlobalNavigatorKey Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Render a custom toast message using showCustom() by providing the overlayState obtained from a GlobalNavigatorKey. This allows for custom UI toasts even without direct BuildContext access. ```dart toastification.showCustom( overlayState: navigatorKey.currentState?.overlay, autoCloseDuration: const Duration(seconds: 5), builder: (BuildContext context, ToastificationItem holder) { // Your custom toast widget }, ); ``` -------------------------------- ### toastification.show() Source: https://context7.com/payam-zahedi/toastification/llms.txt Displays a toast notification with customizable content, styling, and behavior. ```APIDOC ## toastification.show() ### Description Displays a predefined toast message with various types (info, success, warning, error) and styles (flat, fillColored, flatColored, minimal, simple). Returns a ToastificationItem for programmatic dismissal. ### Parameters #### Request Body - **context** (BuildContext) - Required - The build context for the toast. - **title** (Widget) - Required - The title text of the toast. - **type** (ToastificationType) - Optional - The type of toast (info, success, warning, error). - **style** (ToastificationStyle) - Optional - The visual style of the toast. - **description** (Widget) - Optional - The body text of the toast. - **alignment** (Alignment) - Optional - Screen position of the toast. - **autoCloseDuration** (Duration) - Optional - Time before the toast automatically closes. - **icon** (Widget) - Optional - Custom icon to display. - **primaryColor** (Color) - Optional - Primary color for the toast. - **backgroundColor** (Color) - Optional - Background color for the toast. - **callbacks** (ToastificationCallbacks) - Optional - Event handlers for tap, close, and dismiss actions. ### Request Example ```dart toastification.show( context: context, title: const Text('Profile updated!'), type: ToastificationType.success, style: ToastificationStyle.flat, autoCloseDuration: const Duration(seconds: 3), ); ``` ### Response #### Success Response (200) - **ToastificationItem** (Object) - Returns an item instance that can be used to dismiss the notification programmatically. ``` -------------------------------- ### Implement Toastification Styles in Flutter Source: https://context7.com/payam-zahedi/toastification/llms.txt Demonstrates how to trigger different toast styles using the toastification.show method within a Flutter widget. ```dart import 'package:flutter/material.dart'; import 'package:toastification/toastification.dart'; class StyleExamples extends StatelessWidget { const StyleExamples({super.key}); @override Widget build(BuildContext context) { return Wrap( spacing: 8, runSpacing: 8, children: [ // Flat style - subtle border, no background fill ElevatedButton( onPressed: () => toastification.show( context: context, type: ToastificationType.success, style: ToastificationStyle.flat, title: const Text('Flat Style'), description: const Text('Clean design with subtle border'), autoCloseDuration: const Duration(seconds: 3), ), child: const Text('Flat'), ), // Fill Colored - solid colored background ElevatedButton( onPressed: () => toastification.show( context: context, type: ToastificationType.success, style: ToastificationStyle.fillColored, title: const Text('Fill Colored Style'), description: const Text('Bold solid background'), autoCloseDuration: const Duration(seconds: 3), ), child: const Text('Fill Colored'), ), // Flat Colored - colored borders and text ElevatedButton( onPressed: () => toastification.show( context: context, type: ToastificationType.warning, style: ToastificationStyle.flatColored, title: const Text('Flat Colored Style'), description: const Text('Colored border without fill'), autoCloseDuration: const Duration(seconds: 3), ), child: const Text('Flat Colored'), ), // Minimal - sleek with accent line ElevatedButton( onPressed: () => toastification.show( context: context, type: ToastificationType.info, style: ToastificationStyle.minimal, title: const Text('Minimal Style'), description: const Text('Modern minimal design'), autoCloseDuration: const Duration(seconds: 3), ), child: const Text('Minimal'), ), // Simple - text only ElevatedButton( onPressed: () => toastification.show( context: context, type: ToastificationType.info, style: ToastificationStyle.simple, title: const Text('Simple text-only notification'), autoCloseDuration: const Duration(seconds: 3), ), child: const Text('Simple'), ), ], ); } } ``` -------------------------------- ### Customize toast appearance and behavior Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Pass additional parameters to the show method to configure styling, animations, callbacks, and interaction settings. ```dart toastification.show( context: context, // optional if you use ToastificationWrapper type: ToastificationType.success, style: ToastificationStyle.flat, autoCloseDuration: const Duration(seconds: 5), title: Text('Hello, World!'), // you can also use RichText widget for title and description parameters description: RichText(text: const TextSpan(text: 'This is a sample toast message. ')), alignment: Alignment.topRight, direction: TextDirection.ltr, animationDuration: const Duration(milliseconds: 300), animationBuilder: (context, animation, alignment, child) { return FadeTransition( turns: animation, child: child, ); }, icon: const Icon(Icons.check), showIcon: true, // show or hide the icon primaryColor: Colors.green, backgroundColor: Colors.white, foregroundColor: Colors.black, padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16), margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), borderRadius: BorderRadius.circular(12), boxShadow: const [ BoxShadow( color: Color(0x07000000), blurRadius: 16, offset: Offset(0, 16), spreadRadius: 0, ) ], showProgressBar: true, closeButton: ToastCloseButton( showType: CloseButtonShowType.onHover, buttonBuilder: (context, onClose) { return OutlinedButton.icon( onPressed: onClose, icon: const Icon(Icons.close, size: 20), label: const Text('Close'), ); }, ), closeOnClick: false, pauseOnHover: true, dragToClose: true, applyBlurEffect: true, onHoverMouseCursor: SystemMouseCursors.click, callbacks: ToastificationCallbacks( onTap: (toastItem) => print('Toast ${toastItem.id} tapped'), onCloseButtonTap: (toastItem) => print('Toast ${toastItem.id} close button tapped'), onAutoCompleteCompleted: (toastItem) => print('Toast ${toastItem.id} auto complete completed'), onDismissed: (toastItem) => print('Toast ${toastItem.id} dismissed'), ), ); ``` -------------------------------- ### Implement Custom Toast Animation and Layout Source: https://context7.com/payam-zahedi/toastification/llms.txt A snippet demonstrating a custom animation transition and a card-based layout with an undo action for a toast notification. ```dart begin: const Offset(-1, 0), end: Offset.zero, ).animate(CurvedAnimation( parent: animation, curve: Curves.easeOutCubic, )), child: child, ); }, builder: (context, holder) { return Card( margin: const EdgeInsets.all(16), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), child: Row( mainAxisSize: MainAxisSize.min, children: [ const Icon(Icons.delete_outline), const SizedBox(width: 12), const Text('Item deleted'), const SizedBox(width: 16), TextButton( onPressed: () { // Undo delete action print('Undo pressed'); toastification.dismissById(holder.id); }, child: const Text('UNDO'), ), ], ), ), ); }, ); }, child: const Text('Show Undo Toast'), ), ], ); } } ``` -------------------------------- ### Show Toast Using GlobalNavigatorKey Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Display a standard toast message by accessing the overlayState via a GlobalNavigatorKey, useful when BuildContext is unavailable. Ensure the GlobalNavigatorKey is correctly assigned in your MaterialApp. ```dart toastification.show( overlayState: navigatorKey.currentState?.overlay, autoCloseDuration: const Duration(seconds: 5), title: Text('Hello, World!'), ); ``` -------------------------------- ### Implement Circular Timer Toast UI Source: https://context7.com/payam-zahedi/toastification/llms.txt A snippet demonstrating a custom toast layout featuring a CircularProgressIndicator and text. ```dart children: [ CircularProgressIndicator( value: 1 - value, strokeWidth: 3, backgroundColor: Colors.grey.shade200, ), Text( '${((1 - value) * 8).ceil()}', style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12, ), ), ], ), ); }, ), const SizedBox(width: 16), const Text('Processing your request...'), ], ), ), ); }, ); }, child: const Text('Circular Timer Toast'), ); } } ``` -------------------------------- ### Import Toastification Package Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Import the Toastification package into your Dart file before using its features. ```dart import 'package:toastification/toastification.dart'; ``` -------------------------------- ### Toastification Styles Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Provides an overview of the available predefined styles for toast messages. ```APIDOC ## Toastification Styles ### Description Details the five predefined styles available for toast messages, each with a unique visual presentation. ### Styles 1. **ToastificationStyle.flat** - Description: A simple and clean style with a subtle border and no background fill. Ideal for minimalist notifications. 2. **ToastificationStyle.fillColored** - Description: A bold style with a solid colored background. Perfect for high-visibility alerts. 3. **ToastificationStyle.flatColored** - Description: A balanced style with a flat design, colored borders, and text, but without a solid fill. Great for notifications that need to stand out. 4. **ToastificationStyle.minimal** - Description: A sleek and modern design with minimal elements and an accent line denoting the notification type. Perfect for clean, distraction-free interfaces. 5. **ToastificationStyle.simple** - Description: A straightforward style showing a single line of text. Best for short, simple messages or confirmations. ``` -------------------------------- ### Wrap App with ToastificationWrapper for Contextless Usage Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Wrap your AppWidget with ToastificationWrapper to enable the use of `toastification.show` and `toastification.showCustom` without providing context. ```dart return ToastificationWrapper( child: MaterialApp(), ); ``` -------------------------------- ### Implement Custom Toast Animations in Flutter Source: https://context7.com/payam-zahedi/toastification/llms.txt Demonstrates various custom animation techniques including rotation, scaling, directional sliding, and complex combined transformations using the animationBuilder callback. ```dart import 'package:flutter/material.dart'; import 'package:toastification/toastification.dart'; class AnimationExamples extends StatelessWidget { const AnimationExamples({super.key}); @override Widget build(BuildContext context) { return Column( children: [ // Rotation animation ElevatedButton( onPressed: () => toastification.show( context: context, title: const Text('Spinning entrance!'), type: ToastificationType.success, autoCloseDuration: const Duration(seconds: 3), animationDuration: const Duration(milliseconds: 500), animationBuilder: (context, animation, alignment, child) { return RotationTransition( turns: Tween(begin: 0.5, end: 1.0).animate( CurvedAnimation(parent: animation, curve: Curves.elasticOut), ), child: FadeTransition(opacity: animation, child: child), ); }, ), child: const Text('Rotation Animation'), ), // Scale bounce animation ElevatedButton( onPressed: () => toastification.show( context: context, title: const Text('Bouncy scale!'), type: ToastificationType.info, autoCloseDuration: const Duration(seconds: 3), animationDuration: const Duration(milliseconds: 600), animationBuilder: (context, animation, alignment, child) { return ScaleTransition( scale: Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation(parent: animation, curve: Curves.elasticOut), ), child: child, ); }, ), child: const Text('Scale Bounce'), ), // Slide from specific direction based on alignment ElevatedButton( onPressed: () => toastification.show( context: context, title: const Text('Slide from left'), type: ToastificationType.warning, alignment: Alignment.centerLeft, autoCloseDuration: const Duration(seconds: 3), animationDuration: const Duration(milliseconds: 400), animationBuilder: (context, animation, alignment, child) { // Determine slide direction based on alignment final offset = alignment.x < 0 ? const Offset(-1, 0) // Slide from left : alignment.x > 0 ? const Offset(1, 0) // Slide from right : alignment.y < 0 ? const Offset(0, -1) // Slide from top : const Offset(0, 1); // Slide from bottom return SlideTransition( position: Tween(begin: offset, end: Offset.zero).animate( CurvedAnimation(parent: animation, curve: Curves.easeOutCubic), ), child: FadeTransition(opacity: animation, child: child), ); }, ), child: const Text('Directional Slide'), ), // Complex combined animation ElevatedButton( onPressed: () => toastification.show( context: context, title: const Text('Complex animation'), type: ToastificationType.error, autoCloseDuration: const Duration(seconds: 4), animationDuration: const Duration(milliseconds: 800), animationBuilder: (context, animation, alignment, child) { return AnimatedBuilder( animation: animation, child: child, builder: (context, child) { return Transform.scale( scale: Curves.elasticOut.transform(animation.value), child: Opacity( opacity: animation.value, child: Transform.translate( offset: Offset(0, 50 * (1 - animation.value)), child: child, ), ), ); }, ); }, ), child: const Text('Complex Animation'), ), ], ); } } ``` -------------------------------- ### Display a basic toast message Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Use the show method to display a simple toast notification with a title and auto-close duration. ```dart toastification.show( context: context, // optional if you use ToastificationWrapper title: Text('Hello, world!'), autoCloseDuration: const Duration(seconds: 5), ); ``` -------------------------------- ### Show All Built-in Toast Notification Types Source: https://context7.com/payam-zahedi/toastification/llms.txt Demonstrates how to display all four built-in toast notification types: info, success, warning, and error. Each type has a distinct color and icon. ```dart import 'package:flutter/material.dart'; import 'package:toastification/toastification.dart'; class TypeExamples extends StatelessWidget { const TypeExamples({super.key}); void showAllTypes(BuildContext context) { // Built-in types final types = [ ToastificationType.info, // Blue color, info icon ToastificationType.success, // Green color, checkmark icon ToastificationType.warning, // Orange color, warning icon ToastificationType.error, // Red color, close icon ]; for (final type in types) { toastification.show( context: context, type: type, title: Text('${type.name.toUpperCase()} notification'), description: Text('This is a ${type.name} message'), autoCloseDuration: const Duration(seconds: 4), ); } } void showCustomType(BuildContext context) { // Create a custom type with your own color and icon const customType = ToastificationType.custom( 'celebration', Colors.purple, Icons.celebration, ); toastification.show( context: context, type: customType, style: ToastificationStyle.fillColored, title: const Text('Custom Celebration!'), description: const Text('You created a custom toast type!'), autoCloseDuration: const Duration(seconds: 5), ); } @override Widget build(BuildContext context) { return Column( children: [ ElevatedButton( onPressed: () => showAllTypes(context), child: const Text('Show All Built-in Types'), ), ElevatedButton( onPressed: () => showCustomType(context), child: const Text('Show Custom Type'), ), ], ); } } ``` -------------------------------- ### Displaying Toast Notifications in Flutter Source: https://context7.com/payam-zahedi/toastification/llms.txt Demonstrates various configurations for toast notifications including success, error, warning, and simple styles using the toastification package. ```dart import 'package:flutter/material.dart'; import 'package:toastification/toastification.dart'; class NotificationExamples extends StatelessWidget { const NotificationExamples({super.key}); @override Widget build(BuildContext context) { return Column( children: [ // Basic success toast ElevatedButton( onPressed: () { toastification.show( context: context, title: const Text('Profile updated!'), type: ToastificationType.success, style: ToastificationStyle.flat, autoCloseDuration: const Duration(seconds: 3), ); }, child: const Text('Show Success Toast'), ), // Detailed error toast with all customization options ElevatedButton( onPressed: () { toastification.show( context: context, type: ToastificationType.error, style: ToastificationStyle.fillColored, title: const Text('Connection Failed'), description: RichText( text: const TextSpan( text: 'Unable to connect to the server. Please check your internet connection.', style: TextStyle(color: Colors.white70), ), ), alignment: Alignment.topRight, direction: TextDirection.ltr, autoCloseDuration: const Duration(seconds: 5), animationDuration: const Duration(milliseconds: 300), icon: const Icon(Icons.wifi_off, color: Colors.white), showIcon: true, primaryColor: Colors.red, backgroundColor: Colors.red.shade800, foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16), margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.red.withOpacity(0.3), blurRadius: 16, offset: const Offset(0, 8), ), ], showProgressBar: true, closeButton: ToastCloseButton( showType: CloseButtonShowType.onHover, ), closeOnClick: false, pauseOnHover: true, dragToClose: true, applyBlurEffect: true, callbacks: ToastificationCallbacks( onTap: (item) => print('Toast tapped: ${item.id}'), onCloseButtonTap: (item) => print('Close button tapped'), onAutoCompleteCompleted: (item) => print('Auto closed'), onDismissed: (item) => print('Toast dismissed'), ), ); }, child: const Text('Show Detailed Error Toast'), ), // Warning toast with minimal style ElevatedButton( onPressed: () { toastification.show( context: context, type: ToastificationType.warning, style: ToastificationStyle.minimal, title: const Text('Low Storage'), description: const Text('Your device storage is almost full.'), autoCloseDuration: const Duration(seconds: 4), ); }, child: const Text('Show Warning Toast'), ), // Info toast with simple style (text only) ElevatedButton( onPressed: () { toastification.show( context: context, type: ToastificationType.info, style: ToastificationStyle.simple, title: const Text('Tip: Double-tap to zoom'), autoCloseDuration: const Duration(seconds: 2), ); }, child: const Text('Show Simple Info Toast'), ), ], ); } } ``` -------------------------------- ### Create Multiple Toasts Source: https://context7.com/payam-zahedi/toastification/llms.txt Creates a loop to display five informational toasts, each with a unique number and a long auto-close duration. The last created toast is stored in `_lastToast` for potential later dismissal. ```dart ElevatedButton( onPressed: () { for (int i = 1; i <= 5; i++) { _lastToast = toastification.show( context: context, title: Text('Notification #$i'), type: ToastificationType.info, autoCloseDuration: const Duration(seconds: 30), ); } }, child: const Text('Create 5 Toasts'), ) ``` -------------------------------- ### Apply Global Toast Configuration Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Wrap the MaterialApp builder with ToastificationConfigProvider to set default toast behavior across the entire application. ```dart class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Toastification', builder: (context, child) { return ToastificationConfigProvider( config: const ToastificationConfig( margin: EdgeInsets.fromLTRB(0, 16, 0, 110), alignment: Alignment.center, itemWidth: 440, animationDuration: Duration(milliseconds: 500), blockBackgroundInteraction: false, ), child: child!, ); }, ); } } ``` -------------------------------- ### Create GlobalNavigatorKey for Context-Independent Toasts Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Define a GlobalKey to manage navigation outside of a widget's BuildContext. This key must be assigned to your MaterialApp's navigatorKey property. ```dart final GlobalKey globalNavigatorKey = GlobalKey(); ``` ```dart MaterialApp( navigatorKey: navigatorKey, // ... other properties ) ``` -------------------------------- ### Implement ToastificationWrapper for Context-Free Toasts Source: https://context7.com/payam-zahedi/toastification/llms.txt Wrap the MaterialApp with ToastificationWrapper to enable toast notifications from anywhere in the application without requiring BuildContext. ```dart import 'package:flutter/material.dart'; import 'package:toastification/toastification.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { // Wrap your MaterialApp with ToastificationWrapper return ToastificationWrapper( child: MaterialApp( title: 'My App', home: const HomePage(), ), ); } } // Now you can show toasts from anywhere without context class ApiService { Future fetchData() async { try { // API call... toastification.show( title: const Text('Data loaded successfully!'), type: ToastificationType.success, autoCloseDuration: const Duration(seconds: 3), ); } catch (e) { toastification.show( title: const Text('Failed to load data'), type: ToastificationType.error, autoCloseDuration: const Duration(seconds: 5), ); } } } ``` -------------------------------- ### Apply Page-Specific Toast Configuration Source: https://github.com/payam-zahedi/toastification/blob/main/README.md Wrap a specific page's widget tree with ToastificationConfigProvider to override default toast settings for that page only. ```dart class HomePage extends StatelessWidget { const HomePage({super.key}); @override Widget build(BuildContext context) { return const ToastificationConfigProvider( config: ToastificationConfig( margin: EdgeInsets.fromLTRB(0, 16, 0, 110), alignment: Alignment.center, itemWidth: 440, animationDuration: Duration(milliseconds: 500), blockBackgroundInteraction: false, ), child: Scaffold( body: HomeBody(), ), ); } } ``` -------------------------------- ### Configure ToastCloseButton Visibility Source: https://context7.com/payam-zahedi/toastification/llms.txt Demonstrates different `CloseButtonShowType` options for the close button. Use `always` for constant visibility, `onHover` to show only when the mouse is over the toast, and `none` to hide the button entirely, relying on swipe gestures for dismissal. ```dart import 'package:flutter/material.dart'; import 'package:toastification/toastification.dart'; class CloseButtonExamples extends StatelessWidget { const CloseButtonExamples({super.key}); @override Widget build(BuildContext context) { return Column( children: [ // Always visible close button (default) ElevatedButton( onPressed: () => toastification.show( context: context, title: const Text('Always visible close'), type: ToastificationType.info, autoCloseDuration: const Duration(seconds: 5), closeButton: const ToastCloseButton( showType: CloseButtonShowType.always, ), ), child: const Text('Always Visible'), ), // Show on hover only ElevatedButton( onPressed: () => toastification.show( context: context, title: const Text('Hover to see close button'), type: ToastificationType.info, autoCloseDuration: const Duration(seconds: 5), closeButton: const ToastCloseButton( showType: CloseButtonShowType.onHover, ), ), child: const Text('On Hover'), ), // No close button ElevatedButton( onPressed: () => toastification.show( context: context, title: const Text('No close button - swipe to dismiss'), type: ToastificationType.info, autoCloseDuration: const Duration(seconds: 5), dragToClose: true, closeButton: const ToastCloseButton( showType: CloseButtonShowType.none, ), ), child: const Text('No Close Button'), ), // Custom close button design ElevatedButton( onPressed: () => toastification.show( context: context, title: const Text('Custom close button'), type: ToastificationType.success, autoCloseDuration: const Duration(seconds: 8), closeButton: ToastCloseButton( showType: CloseButtonShowType.always, buttonBuilder: (context, onClose) { return TextButton.icon( onPressed: onClose, icon: const Icon(Icons.check, size: 18), label: const Text('Got it'), style: TextButton.styleFrom( foregroundColor: Colors.green.shade700, padding: const EdgeInsets.symmetric(horizontal: 12), ), ); }, ), ), child: const Text('Custom Button'), ), ], ); } } ``` -------------------------------- ### Build Circular Progress Indicator for Toast Source: https://context7.com/payam-zahedi/toastification/llms.txt Integrate ToastTimerAnimationBuilder to create a circular progress indicator for a toast, synchronizing its animation with the toast's auto-close timer. ```dart // Circular progress indicator example class CircularTimerToast extends StatelessWidget { const CircularTimerToast({super.key}); @override Widget build(BuildContext context) { return ElevatedButton( onPressed: () { toastification.showCustom( context: context, autoCloseDuration: const Duration(seconds: 8), builder: (context, holder) { return Card( margin: const EdgeInsets.all(16), child: Padding( padding: const EdgeInsets.all(16), child: Row( mainAxisSize: MainAxisSize.min, children: [ ToastTimerAnimationBuilder( item: holder, builder: (context, value, child) { return SizedBox( width: 40, height: 40, child: Stack( alignment: Alignment.center, ```