flutter_sonner 1.2.0
flutter_sonner: ^1.2.0 copied to clipboard
An opinionated stacked action toast and notification HUD for Flutter inspired by Sonner. Spring physics, card depth stacking, and promise toasts.
flutter_sonner #
An opinionated, elegant stacked action toast and notification HUD for Flutter, inspired by Emil Kowalski's Sonner. Built with card-depth stacking, spring physics, interactive action buttons, promise-based async toasts, and horizontal swipe-to-dismiss gestures.
⚡ Why flutter_sonner? #
Standard notifications in Flutter often fall short of modern UX expectations:
- 🚫 Clunky SnackBars: Push floating action buttons (FABs), cover bottom navigation bars, and lack clean depth stacking when multiple alerts trigger simultaneously.
- 🚫 Rigid Native Toasts: OS-native toasts (like Android
Toast) cannot host interactive buttons ("Undo", "Retry", "View"), have fixed styling, and lack dismiss gestures. - 🚫 No Async Promise Binding: Tracking the lifecycle of an upload, network mutation, or checkout usually requires writing complex boilerplate to swap loading dialogs with success banners.
flutter_sonner delivers an ultra-smooth, lightweight, pure Flutter overlay system with stacked card depth.
🚀 Features #
| Feature | Description |
|---|---|
| 🃏 Card-Depth Stacking | Earlier notifications peek smoothly behind the active front card with spring-scaled depth (0.95x, 0.90x) and elevation drop shadows. |
| ✨ Expand on Hover / Long Press | Hovering mouse or holding on mobile gracefully unfolds the stack into a full scrollable column. |
| ⚡ Interactive Action Buttons | Embed pill buttons (Undo, Retry, View) with instant tap dispatch. |
| 🔄 Seamless Promise Toasts | Sonner.promise(...) automatically handles loading spinner ➔ in-place transition to success or error. |
| 👉 Natural Swipe to Dismiss | Swipe left or right with velocity-aware dismiss physics and smooth opacity fade. |
| 📍 Multi-Position Anchors | bottomRight, bottomCenter, bottomLeft, topRight, topCenter, topLeft. |
| 🎨 3 Design Presets | SonnerTheme.dark() (Obsidian slate), SonnerTheme.light(), and SonnerTheme.glass() (frosted glassmorphic). |
| 🌐 Multi-Platform | 100% pure Dart & Flutter with zero native dependencies. Works on iOS, Android, Web, macOS, Windows, and Linux. |
📦 Installation #
Add flutter_sonner to your pubspec.yaml:
flutter pub add flutter_sonner
💡 Quick Start #
1. Mount SonnerToaster globally #
Wrap your root MaterialApp.builder:
import 'package:flutter/material.dart';
import 'package:flutter_sonner/flutter_sonner.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
builder: (context, child) {
return SonnerToaster(
position: SonnerPosition.bottomRight,
child: child,
);
},
home: const HomeScreen(),
);
}
}
2. Trigger Toasts anywhere without BuildContext! #
// Success with description
Sonner.success(
'Event created in calendar',
description: 'Monday, October 27 at 10:30 AM',
);
// Interactive Action (Undo / Retry)
Sonner.show(
'File moved to trash',
description: 'Can be restored within 30 days',
action: SonnerAction(
label: 'Undo',
onPressed: () => print('Restored!'),
),
);
// Error alert
Sonner.error(
'Connection timed out',
description: 'Could not reach database cluster.',
action: SonnerAction(label: 'Retry', onPressed: () => retry()),
);
🔄 Async Promise Toasts #
Eliminate boilerplate when tracking asynchronous workflows:
await Sonner.promise<UserProfile>(
api.updateProfile(data),
loading: 'Updating user profile...',
success: (profile) => 'Profile saved for ${profile.name}',
successDescription: (profile) => 'All changes synced with cloud',
error: (err) => 'Failed to save changes: $err',
);
📍 Positioning & Theming #
SonnerToaster(
position: SonnerPosition.topCenter,
theme: SonnerTheme.glass(), // Frosted glassmorphism
expandByDefault: false, // Hover or tap to expand
child: child,
)
Available Presets:
SonnerTheme.dark(): Modern dark slate with high-contrast text.SonnerTheme.light(): Clean paper-white design with crisp border lines.SonnerTheme.glass(): Translucent frosted glass effect.
🔗 Related Packages by Author #
- ai_stream_bubble — High-performance streaming AI message bubble with DeepSeek/Claude reasoning accordions.
- ai_voice_orb — Fluid neural voice orb for Conversational AI & voice agents.
- spatial_card — 3D tactile interactive cards & multi-plane parallax surfaces.
- waveform_pro — GPU-accelerated audio waveform scrubbing & peak visualizer.
💖 Support the Project #
If you find this project useful, consider supporting its active maintenance and future development:
📄 License #
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Maintained with ❤️ by Govind Tank.