Receiver FCM notification click event
872
The onMessage is triggered when you receive a notification and App in Foreground is running.
Please have a look at onResume and onLaunch callbacks. More information you could find on the library page
Author by
Somomo1q
Updated on December 10, 2022Comments
-
Somomo1q over 1 year
How can I receive the notification click event on flutter?
I write this code on main.dart but the onMessage handling events doesn't work.
This code block doesn't work on background too.
When the app working on background onMessage function doesn't handling.
main.dart
FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); void iOS_Permission() { _firebaseMessaging.requestNotificationPermissions( IosNotificationSettings(sound: true, badge: true, alert: true) ); _firebaseMessaging.onIosSettingsRegistered .listen((IosNotificationSettings settings) { print("Settings registered: $settings"); }); } void firebaseCloudMessaging_Listeners(BuildContext context) { if (Platform.isIOS) iOS_Permission(); _firebaseMessaging.getToken().then((token){ print("Token : ${token}"); }); _firebaseMessaging.configure( onMessage: (Map<String, dynamic> message) async { print('on message $message'); }, onResume: (Map<String, dynamic> message) async { print('on resume $message'); }, onLaunch: (Map<String, dynamic> message) async { Navigator.pushNamed(context, "/"); print('on launch $message'); }, ); } void main() { print("uygulama Acildi"); debugPaintSizeEnabled = false; runApp(MaterialApp( localizationsDelegates: [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ],supportedLocales: [ const Locale('tr', 'TR'), ], theme: ThemeData(fontFamily: 'Oswald'), initialRoute: '/', routes: <String, WidgetBuilder>{ // '/': (context) => SanalPulHareketleri(), '/': (context) => SplashEkrani(), '/kayit_ol': (context) => KayitOl(), }, )); }