Big*_*ive 5 messaging firebase flutter
我是扑的新手。我刚刚将一个为我构建的项目升级到 flutter 2.0,我不确定如何解决这个特定问题。我用谷歌搜索并找到了例子。我知道这里有改进,可能会解决我的应用程序面临的问题之一。但我不知道如何调整这个特定的代码部分,因为它比我在网上找到的任何例子都要复杂。希望有人能指出我正确的方向。
void initFCMNotification() {
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
mapEntry = message;
String type =
message['Notificationtype'] ?? message['data']['Notificationtype'];
print("notification onMessage $type");
if (type == '5' || type == '11' || type == '3') {
Function reload = context.read<EventsProvider>().reload;
Future.delayed(Duration(seconds: 1), () {
reload(true);
});
} else if (type == '4') {
var notification = getNotification(message);
nav.currentState.push(MaterialPageRoute(
builder: (context) => MeetAgainScreen(notification)));
}
if (type != '11') {
if (Platform.isIOS) {
notiType = message['Notificationtype'];
print('isIOS on message ${message['aps']['alert']['title']}');
if (type == "0") {
reloadData(type, message);
} else {
showSilentNotification(flutterLocalNotificationsPlugin,
title:
"${message['title'] ?? message['aps']['alert']['title'] ?? message['notification']['title'] ?? ''}",
payload: "${message['Notificationtype'] ?? ''}",
body:
"${message['body'] ?? message['aps']['alert']['body'] ?? message['notification']['body'] ?? ''}",
id: 1);
}
} else if (Platform.isAndroid) {
notiType = message['data']['Notificationtype'];
print('Android on message /*${message['data']['body']}*/');
if (type == "0") {
reloadData(type, message);
} else {
showSilentNotification(flutterLocalNotificationsPlugin,
title:
"${message['data']['title'] ?? message['notification']['title'] ?? ''}",
payload: "${message['data']['Notificationtype'] ?? ''}",
body:
"${message['data']['body'] ?? message['notification']['body'] ?? ''}",
id: 1);
}
}
}
Run Code Online (Sandbox Code Playgroud)
从版本 8.0.0-dev.1 开始,configure()已被删除以支持调用返回Streams.
您应该使用FirebaseMessaging.onMessage(),FirebaseMessaging.onMessageOpenedApp()代替。
这里的例子
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
...
});
Run Code Online (Sandbox Code Playgroud)
您可以在此pub 的更新日志中找到更多信息。
| 归档时间: |
|
| 查看次数: |
3079 次 |
| 最近记录: |