Alerts, toasts, loaders, and haptic/sound feedback for Flutter apps. Flashly provides a consistent, platform-aware UI layer for transient messages and modal dialogs, with optional Lottie animations and native-style styling.
| Success | Error |
|---|---|
![]() |
![]() |
| Warning | Loader |
|---|---|
![]() |
![]() |
| Success | Error | Info |
|---|---|---|
![]() |
![]() |
![]() |
- Modal alerts — success, error, info, and warning states with Lottie icons
- Toasts — animated overlay messages with swipe-to-dismiss
- Loader alerts — blocking dialogs with a loading animation and optional auto-close
- Inline loaders — adaptive
CircularProgressIndicatoror Lottie spinner - Haptic feedback — built-in vibration on button presses and optional alert/toast triggers
- Sound feedback — optional audio cues via
audioplayers - Platform styling — frosted-glass alerts on iOS, Material styling on Android
- Dart SDK
>=3.12.0 <4.0.0 - Flutter
>=3.44.0
Add flashly to your pubspec.yaml:
dependencies:
flashly:
path: ../packages/flashly # adjust path as neededThen run:
flutter pub getFlashly uses global keys to show overlays and dialogs without requiring a BuildContext in every call. Wire them into your root MaterialApp:
import 'package:flashly/flashly.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: Flashly.navigatorKey,
scaffoldMessengerKey: Flashly.scaffoldMessengerKey,
home: const HomePage(),
);
}
}When navigatorKey is set, showToast and showAlert (without an explicit context) resolve the overlay from the root navigator. You can still pass a BuildContext to showAlert when you need a local navigator scope.
Display a modal dialog with optional title, description, and action buttons:
showAlert(
'Operation completed',
description: 'Your data was saved successfully.',
positiveTitle: 'OK',
state: AlertState.success,
context: context,
);Two-button alert with a destructive action:
showAlert(
'Something went wrong',
description: 'The operation could not be completed.',
negativeTitle: 'Cancel',
positiveTitle: 'Try again',
state: AlertState.error,
isDestructive: true,
onPositive: () async {
// retry logic
},
context: context,
);Available AlertState values: success, error, info, warning.
| Parameter | Description |
|---|---|
title |
Main heading text |
description |
Body text below the title |
richTitle / richDescription |
Secondary tappable text appended to title or description |
negativeTitle |
Left/cancel button label (defaults to "Cancelar") |
positiveTitle |
Right/confirm button label; omit for a single-button dialog |
state |
Shows a Lottie animation matching the alert type |
isDestructive |
Styles the positive button as destructive (red) |
onNegative / onPositive |
Callbacks when buttons are pressed |
enableHaptics / enableSound |
Trigger feedback when the alert opens |
radius / actionButtonRadius |
Corner radius for the dialog and buttons |
Show a short-lived message at the bottom of the screen:
showToast('Copied to clipboard');
showToast(
'Failed to send',
state: ToastState.error,
);
showToast(
'Sync in progress',
state: ToastState.info,
duration: const Duration(seconds: 5),
);Available ToastState values: success, error, info.
Toasts slide in from the bottom, auto-dismiss after 3 seconds (configurable), and can be swiped down to dismiss early.
| Parameter | Description |
|---|---|
message |
Primary toast text |
richMessage |
Secondary tappable text appended to the message |
state |
Controls the default icon and color |
icon / iconColor |
Override the default state icon |
duration |
How long the toast stays visible (default: 3 s) |
enableHaptics / enableSound |
Trigger feedback when the toast appears |
Show a blocking loading dialog:
showLoaderAlert(
placeholder: 'Loading',
closeLoaderAfterSecs: 45,
context: context,
);After closeLoaderAfterSecs (default: 45), a Close button fades in so the user can dismiss the dialog manually. Close it programmatically with:
closeLoaderAlert();For a timed loader that auto-closes:
showTimingLoaderAlert('Please wait', 3); // closes after 3 secondsEmbed a spinner in your own widgets:
loader(color: Theme.of(context).colorScheme.primary)
loader(
size: 32,
asNative: false, // use Lottie animation instead of CircularProgressIndicator
)Trigger feedback independently:
haptics(impact: HapticImpact.medium);
await playSound(); // success sound
await playSound(true); // error soundWrap any VoidCallback with automatic haptics:
onPressed: myCallback.hapticCallback,Flashly also exports building blocks you can use directly:
AlertActionButton— styled dialog action button with press effectPressEffect— scale/opacity animation on tapTxt/RichTxt— text widgets used inside alerts and toasts
Sound feedback expects success.mp3 and error.mp3 in your app's asset bundle. Add them to your app's pubspec.yaml:
flutter:
assets:
- assets/sounds/success.mp3
- assets/sounds/error.mp3Then update the paths in playSound or call playAlert / playAudio directly with your asset paths.
An interactive demo is included in the example/ directory:
cd example
flutter runThe example covers all alert states, toast variants, loader alerts, and standalone widgets.
lib/
├── flashly.dart # Public API exports
└── src/
├── core/
│ └── flashly.dart # Global navigator/messenger keys
├── alerts/
│ ├── show_alert.dart # showAlert() dialog builder
│ └── alert_state.dart # AlertState enum
├── toasts/
│ ├── show_toast.dart # showToast() overlay insertion
│ ├── animated_toast.dart
│ └── toast_state.dart # ToastState enum
├── loaders/
│ ├── loader_alert.dart # showLoaderAlert, closeLoaderAlert
│ └── flashly_loader.dart
├── feedback/
│ ├── haptic_feedback.dart
│ └── sound_feedback.dart
├── audio/
│ └── audio_service.dart
├── widgets/
│ ├── alert_container.dart # Frosted-glass dialog shell
│ ├── alert_action_button.dart
│ ├── lottie_animation.dart
│ ├── press_effect.dart
│ ├── txt.dart
│ └── rich_txt.dart
├── constants/
│ ├── animation_assets.dart
│ └── colors.dart
└── extensions/
└── haptic_callback.dart
Alerts are built on Flutter's showDialog. The AlertContainer widget applies platform-specific styling — backdrop blur and gradient borders on iOS, solid card color on Android. State-specific Lottie animations are loaded from the package's bundled assets via FlashlyAnimations.
Toasts are inserted directly into the navigator overlay as an OverlayEntry. AnimatedToast handles slide/fade entrance, auto-dismiss timer, and vertical drag-to-dismiss gestures.
Loader alerts reuse the alert dialog with asLoader: true, showing a Lottie loading animation beside the placeholder text. A StatefulBuilder reveals the close button after the configured timeout.
Loaders default to CircularProgressIndicator.adaptive with optional color tinting. Set asNative: false to use the Lottie loading animation instead.
| Package | Purpose |
|---|---|
lottie |
State icons and loading animations |
audioplayers |
Optional sound feedback |
See the repository for license details.







