swift_alert library
SwiftAlert: Beautiful, customizable notification banners for Flutter.
SwiftAlert makes it easy to show animated, top-of-screen notification alerts in your Flutter app.
Features:
- Multiple notification types (success, error, info, warning)
- Smooth animations and overlay handling
- Customizable appearance and easy integration
- No context required after initialization
Getting Started
1. Initialize SwiftAlert at app startup:
void main() {
final navigatorKey = GlobalKey<NavigatorState>();
SwiftAlert.initialize(navigatorKey: navigatorKey);
runApp(MyApp(navigatorKey: navigatorKey));
}
2. Pass the navigator key to MaterialApp:
class MyApp extends StatelessWidget {
final GlobalKey<NavigatorState> navigatorKey;
const MyApp({required this.navigatorKey});
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: navigatorKey,
home: HomePage(),
);
}
}
3. Show notifications anywhere without context:
SwiftAlert.show(
message: 'Profile updated!',
type: NotificationType.success,
);
Legacy Usage (with context)
You can still use the old API with context if needed:
SwiftAlert.display(
context,
message: 'Profile updated!',
type: NotificationType.success,
);