riverpod_toast 0.1.0
riverpod_toast: ^0.1.0 copied to clipboard
A Riverpod-based toast notification system with overlay support, localization, and adaptive theming.
riverpod_toast #
riverpod_toast is a modular, high-performance toast system built with Riverpod v3 and flutter_styled_toast.
โจ Features #
- Overlay-based toast display
- Riverpod-based logic
- Localization-ready
- Adaptive dark/light theming
- Tap-to-dismiss
- Throttling and deduplication
โ Usage #
- Register context:
ref.read(toastControllerProvider.notifier).registerContext(context);
- Show toast:
showSuccess(ref, 'toast_success');
Add this to your pubspec.yaml:
dependencies:
riverpod_toast:
path: ./packages/riverpod_toast
๐ riverpod_toast #
Elegant, flexible, and context-free toast notifications for Flutter, powered by Riverpod & Styled Toast.
๐ Tagline #
"RiverpodToast โ Show toasts anywhere, powered by Riverpod and overlay magic."
๐ฏ Overview #
riverpod_toast is a reusable Flutter toast system designed for real-world apps.
Built on top of flutter_styled_toast, Riverpod, and EasyLocalization, it gives you:
- Queueing
- Deduplication
- Adaptive dark mode styling
- Context-free invocation
- Global customization
- Easy integration with localization
โจ Features #
โ
Context-free toast โ Show toast from anywhere in your app logic, no need for BuildContext
โ
Toast queue โ Handles multiple toast requests without overlap
โ
Smart deduplication โ Prevents spamming the same toast repeatedly
โ
Dark mode support โ Auto-styled based on current theme
โ
Riverpod-based state โ Full control, observability, and testability
โ
Modular โ Easily reusable in any Flutter app
โ
Custom animations & positioning โ Built on top of flutter_styled_toast
โ
EasyLocalization integration โ Optional auto-localized messages
โ
No external dependencies like fluttertoast
โ๏ธ Comparison #
| Feature | riverpod_toast |
ScaffoldMessenger |
fluttertoast |
|---|---|---|---|
| No context needed | โ | โ | โ |
| Works in overlays/dialogs | โ | โ | โ |
| Queueing | โ | โ | โ |
| Deduplication | โ | โ | โ |
| EasyLocalization support | โ | โ | โ |
| Riverpod integration | โ | โ | โ |
| Custom animation & styling | โ | โ ๏ธ | โ ๏ธ |
| Platform-native support | โ | โ | โ |
| Built-in Material Design feel | โ ๏ธ | โ | โ |
๐งฉ Installation #
flutter pub add riverpod_toast
Make sure to also have: (see example/pubspec.yaml)
dependencies:
flutter_riverpod: ^3.0.0
riverpod_annotation: ^3.0.0
easy_localization: ^3.0.8
flutter_styled_toast: ^2.2.1
build_runner:
riverpod_generator:
๐ ๏ธ Setup #
1. Wrap your app with ProviderScope and EasyLocalization
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
runApp(
ProviderScope(
child: EasyLocalization(
supportedLocales: const [Locale('en')],
path: 'assets/translations',
fallbackLocale: const Locale('en'),
child: const MyApp(),
),
),
);
}
2. Register context after StyledToast is mounted
class MyApp extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
return StyledToast(
locale: context.locale,
child: MaterialApp(
home: ToastContextRegistrar(
child: const HomePage(),
),
),
);
}
}
class ToastContextRegistrar extends ConsumerStatefulWidget {
final Widget child;
const ToastContextRegistrar({required this.child});
@override
ConsumerState<ToastContextRegistrar> createState() => _ToastContextRegistrarState();
}
class _ToastContextRegistrarState extends ConsumerState<ToastContextRegistrar> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
ref.read(toastControllerProvider.notifier).registerContext(context);
});
}
@override
Widget build(BuildContext context) => widget.child;
}
โ Usage #
In any widget or service:
showSuccess(ref, 'Operation successful');
showError(ref, 'Something went wrong!');
showWarning(ref, 'Be careful!');
showInfo(ref, 'This is an info message');
You donโt need to pass
contextโ itโs already registered via Riverpod.
๐ Dark Mode & Styling #
Toasts adapt automatically based on the theme.
You can customize animations, padding, colors, border radius, etc., by editing ToastController._buildToastWidget(...).
๐ Localization #
If you're using EasyLocalization, toast messages can be translated automatically:
showSuccess(ref, 'msg_operation_successful'.tr());
You can also configure whether a message should be treated as localized using the localized flag in show().
๐งช Testing & Debugging #
You can inspect the internal queue using:
final queue = ref.watch(toastControllerProvider);
Logs are printed during registration, deduplication, and toast display.
๐ฆ Folder Structure #
lib/riverpod_toast.dart: main exportsrc/toast_controller.dart: Riverpod notifier with queue/dedupe logicsrc/toast_type.dart: enum for toast typessrc/toast_helpers.dart: exposed functions likeshowSuccess()
๐ฎ Coming Soon #
โ
ToastScope widget โ auto-registers context with no boilerplate
โ
Actionable toasts โ support for actions like UNDO, RETRY, etc.
โ
Global fallback to ScaffoldMessenger if overlay not available
โ
Adaptive styling hooks for Material 3 & platform UI
โ
Configuration builder for themes, durations, animation styles
โ
Optional ToastTheme override per toast
โ
Support for persistent toasts with dismiss buttons
๐ค Contribution #
Feel free to open issues or submit PRs. Weโre keeping this package modular, Riverpod-native, and customizable.
๐ License #
MIT โ use freely for personal or commercial projects.
Made with โค๏ธ by [sumitsharansatsangi].