Professional Documents
Culture Documents
await _notificationsPlugin.show(
id,
message.notification!.title,
message.notification!.body,
notificationDetails,
payload: message.data['_id'],
);
} on Exception catch (e) {
print(e);
}
}
---------------------------------------------------
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) => DemoScreen(
// id: id,
// ),
// ),
// );
}
},
);
--------------------------------------------------
@override
void initState() {
super.initState();
// 1. This method call when app in terminated state and you get a notification
// when you click on notification app open from terminated state and you can
get notification data in this method
FirebaseMessaging.instance.getInitialMessage().then(
(message) {
print("FirebaseMessaging.instance.getInitialMessage");
if (message != null) {
print("New Notification");
// if (message.data['_id'] != null) {
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) => DemoScreen(
// id: message.data['_id'],
// ),
// ),
// );
// }
LocalNotificationService.createanddisplaynotification(message);
}
},
);
// 2. This method only call when App in forground it mean app must be opened
FirebaseMessaging.onMessage.listen(
(message) {
print("FirebaseMessaging.onMessage.listen");
if (message.notification != null) {
print(message.notification!.title);
print(message.notification!.body);
print("message.data11 ${message.data}");
LocalNotificationService.createanddisplaynotification(message);
}
},
);
// 3. This method only call when App in background and not terminated(not
closed)
FirebaseMessaging.onMessageOpenedApp.listen(
(message) {
print("FirebaseMessaging.onMessageOpenedApp.listen");
if (message.notification != null) {
print(message.notification!.title);
print(message.notification!.body);
print("message.data22 ${message.data['_id']}");
LocalNotificationService.createanddisplaynotification(message);
}
},
);
// getToken();
}
// Future<void> getToken()async{
// final response = await FirebaseMessaging.instance.getToken();
// print(response);
// }
------------------------------------------------------------------------
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="High_importance_channel" />
try{
final response = await dio.post('https://fcm.googleapis.com/fcm/send',
data: {
"notification": {
"title": "hello firbase project",
"body": message.text,
"android_channel_id": "High_importance_channel"
},
"to":
"fzL5E8xZQ9654MiZ2Sdua3:APA91bGfUI89fdMzwVwdjJNBGMSDQTZBlaPkC9k67nAF06F4nCq1qtbVmlL
k8FwM1sUih0_kKEj-fv6Y8RQMgJHG5zrfKc2Q_I1cQ8d9g0zG4nadvBNnSQDiPVSgjCGNf9lpmpCH5o01"
}, options: Options(
headers: {
HttpHeaders.authorizationHeader :
'key=AAAAWyskt5c:APA91bFpl2KNnos1ikmF80Z8sTq3uB7TfldnEzmcIr0YYdX3xJz21AXLK1YWNbY31q
NdL7wiEZCFzfrklTqNe8NY14A51I-zWCqXHuanugW5ukf_di55VcSGk1bynfk7BVJ17BZ9HGtC'
}
)
);
print(response.data);