flutter_nice_toast 0.2.5 copy "flutter_nice_toast: ^0.2.5" to clipboard
flutter_nice_toast: ^0.2.5 copied to clipboard

A beautiful, customizable toast notification package for Flutter with animations and various styles.

Flutter Nice Toast #

A beautiful and highly customizable toast notification package for Flutter with animations and various predefined styles. Shows toasts without requiring BuildContext.

📱 Screenshots #

Flutter Nice Toast Demo

Top Position Toast Center Position Toast Bottom Position Toast
Top Position Center Position Bottom Position

Features #

  • 🎨 Elegant Design: Stylish and clean toast notifications with smooth animations
  • 🔔 Multiple Styles: Pre-built themes for success, error, warning and info toasts
  • 🔧 Highly Customizable: Create your own toast themes with custom colors, icons, and gradients
  • 📱 Flexible Positioning: Display toasts at the top, center, or bottom of the screen
  • 🖱️ Interactive: Support for dismissal by swipe, tap callbacks, and persistent toasts
  • Simple API: Clean, intuitive API for easy implementation
  • 🧩 No Context Required: Display toasts from anywhere in your app without BuildContext

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_nice_toast: ^0.1.0

Then run:

flutter pub get

Usage #

Import the package:

import 'package:flutter_nice_toast/flutter_nice_toast.dart';

Setup #

First, initialize the toast system in your app's entry point and add the navigator key to your MaterialApp:

void main() {
  // Initialize NiceToast and get the navigator key
  final navigatorKey = NiceToast.init();
  
  runApp(MyApp(navigatorKey: navigatorKey));
}

class MyApp extends StatelessWidget {
  final GlobalKey<NavigatorState> navigatorKey;
  
  const MyApp({super.key, required this.navigatorKey});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // Set the navigator key to enable context-free toast display
      navigatorKey: navigatorKey,
      home: HomePage(),
      // Other app configurations...
    );
  }
}

Basic Usage #

Show predefined toast notifications from anywhere in your app without BuildContext:

// Show an error toast
NiceToast.error(
  message: "An error occurred!",
  title: "Error", // Optional
);

// Show a success toast
NiceToast.success(
  message: "Operation completed successfully!",
  title: "Success", // Optional
);

// Show a warning toast
NiceToast.warning(
  message: "Please proceed with caution!",
  title: "Warning", // Optional
);

// Show an info toast
NiceToast.info(
  message: "System will be updated tomorrow.",
  title: "Information", // Optional
);

Customization Options #

All toast types support these customization options:

NiceToast.success(
  message: "Operation completed successfully!",
  title: "Success",
  position: ToastPosition.top, // top (default), center, or bottom
  duration: const Duration(seconds: 5), // Duration before auto-dismiss
  margin: 50.0, // Margin from the screen edge
  dismissible: true, // Allow swipe to dismiss
  onDismiss: () {
    // Handle toast dismissal
  },
  onTap: () {
    // Handle toast tap
  },
);

Persistent Toasts #

Display toasts that don't auto-dismiss and require user action to close:

NiceToast.errorPersistent(
  message: "This error requires your attention!",
  title: "Critical Error",
);

Persistent versions are available for all toast types: successPersistent, warningPersistent, infoPersistent.

Custom Toasts #

Create your own toast themes:

final customTheme = ToastTheme(
  backgroundColor: Colors.purple,
  borderColor: Colors.deepPurple,
  iconData: Icons.stars,
  textColor: Colors.white,
  iconColor: Colors.white,
  gradient: LinearGradient(
    begin: Alignment.topLeft,
    end: Alignment.bottomRight,
    colors: [Colors.purple, Colors.deepPurple],
  ),
  borderRadius: 12.0,
  borderWidth: 1.5,
  padding: EdgeInsets.symmetric(horizontal: 20, vertical: 16),
);

NiceToast.custom(
  message: "This is a completely custom toast!",
  title: "Custom Toast",
  theme: customTheme,
  position: ToastPosition.center,
);

Manually Dismissing Toasts #

You can programmatically dismiss the current toast:

NiceToast.dismiss();

Example #

See the /example directory for a complete demo app.

License #

This package is available under the MIT License.

9
likes
150
points
224
downloads

Publisher

verified publisheryasinatagun.com

Weekly Downloads

A beautiful, customizable toast notification package for Flutter with animations and various styles.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on flutter_nice_toast