Flutter Notifications
ASecurityFrom scratch, the usual package set is: - `firebase_core` — initialize Firebase first - `firebase_messaging` — FCM token, permission, foreground/background/terminated delivery - `flutter_local_notifications` — show local notifications, especially for foreground messages Typical setup flow: 1. Add the packages and install native Firebase config - Flutter: `firebase_core`, `firebase_messaging`, `flutter_local_notifications` - Android: add `google-services.json` - iOS: add `GoogleService-Info.pl...
- 584 stars
- 0 votes
- 0 copies
- 4 views
- Added September 5, 2026
Works with
Security analysis
100/100Pro scans all 12 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill flutter-notifications --agent claude-codeAre you the author of Flutter Notifications?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-flutter-notifications-agent-skills-standard)From scratch, the usual package set is:
- `firebase_core` — initialize Firebase first
- `firebase_messaging` — FCM token, permission, foreground/background/terminated delivery
- `flutter_local_notifications` — show local notifications, especially for foreground messages
Typical setup flow:
1. Add the packages and install native Firebase config
- Flutter: `firebase_core`, `firebase_messaging`, `flutter_local_notifications`
- Android: add `google-services.json`
- iOS: add `GoogleService-Info.plist`
2. Initialize Firebase in `main()`
- `WidgetsFlutterBinding.ensureInitialized()`
- `await Firebase.initializeApp()`
3. Initialize local notifications
- Create a `FlutterLocalNotificationsPlugin`
- Define Android notification channel(s)
- Initialize plugin with tap/click handler
4. Request notification permission
- On iOS (and newer Android flows where relevant), show your own primer first, then call:
- `FirebaseMessaging.instance.requestPermission(...)`
5. Register message handlers for all app states
- Foreground: `FirebaseMessaging.onMessage.listen(...)`
- FCM often won’t display a system banner while app is open, so use `flutter_local_notifications` to display one yourself
- Background: `FirebaseMessaging.onBackgroundMessage(_handler)`
- top-level/static handler
- Terminated/opened from notification:
- `FirebaseMessaging.instance.getInitialMessage()`
- `FirebaseMessaging.onMessageOpenedApp.listen(...)`
6. Get and manage the FCM token
- `await FirebaseMessaging.instance.getToken()`
- send token to your backend
- listen for refresh with `onTokenRefresh`
7. Validate payload data before navigation
- If tapping a notification opens a screen, validate payload keys/IDs first instead of trusting raw data
Minimal initialization shape:
```dart
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
final local = FlutterLocalNotificationsPlugin();
await local.initialize(
const InitializationSettings(
android: AndroidInitializationSettings('@mipmap/ic_launcher'),
iOS: DarwinInitializationSettings(),
),
);
await FirebaseMessaging.instance.requestPermission();
FirebaseMessaging.onMessage.listen((message) {
// show local notification for foreground message
});
FirebaseMessaging.onMessageOpenedApp.listen((message) {
// validate payload, then navigate
});
final initialMessage = await FirebaseMessaging.instance.getInitialMessage();
if (initialMessage != null) {
// app opened from terminated state
}
runApp(const MyApp());
}
```
In short: use `firebase_core + firebase_messaging + flutter_local_notifications`, initialize Firebase first, request permission thoughtfully, then handle foreground, background, and terminated notification flows explicitly.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.