Ad
Receiver FCM Notification Click Event
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(),
},
));
}
Ad
Answer
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
Ad
source: stackoverflow.com
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?
Ad