如果有通知,我正在创建一个推向ChatScreen的推送导航。 它在推动,但问题是它在无限地推动。
我将其用于Firebase消息传递
_firebaseMessaging.configure(
//Display when the apps on close
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch : $message\n");
if (message['data']['type'] == 'like') {
print("Navigate to Notification");
print("type : ${message['data']['type']}");
} else if (message['data']['type'] == 'chat') {
print("userID : ${message['data']['userID']}");
print("sellerID : ${message['data']['sellerID']}");
print("type : ${message['data']['type']}");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatScreen(
userID: message['data']['userID'],
sellerID: message['data']['sellerID'],
productName: "",
firstMessage: "",
price: 0,
imageUrls: [""],
),
),
);
}
},
//Display when the apps on background
onResume: (Map<String, dynamic> message) async {
print("onResume : $message\n");
if (message['data']['type'] == 'like') {
print("Navigate to Notification");
print("type : ${message['data']['type']}");
} else if (message['data']['type'] == 'chat') {
print("userID : ${message['data']['userID']}");
print("sellerID : ${message['data']['sellerID']}");
print("type : ${message['data']['type']}");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatScreen(
userID: message['data']['userID'],
sellerID: message['data']['sellerID'],
productName: "",
firstMessage: "",
price: 0,
imageUrls: [""],
),
),
);
}
},
//Display when the apps is active
onMessage: (Map<String, dynamic> message) async {
print("onMessage : $message\n");
},
);
这是终端上的输出
I/flutter (13793): onLaunch : {data: {google.sent_time: 1568110868915, click_action: FLUTTER_NOTIFICATION_CLICK, userID: IGgqN2pqzKPk6pNN7Sl3NT8mois2, google.original_priority: high, status: done, collapse_key: id.co.sprout.etalase, sellerID: VduOp2mICGcLjQDXFXJVRrkmV6n2, groupChatID: IGgqN2pqzKPk6pNN7Sl3NT8mois2-VduOp2mICGcLjQDXFXJVRrkmV6n2, google.delivered_priority: high, sound: default, from: 11013836573, type: chat, google.message_id: 0:1568110868934877%c5168753c5168753, google.ttl: 2419200}, notification: {}}
I/flutter (13793): userID : IGgqN2pqzKPk6pNN7Sl3NT8mois2
I/flutter (13793): sellerID : VduOp2mICGcLjQDXFXJVRrkmV6n2
I/flutter (13793): type : chat
I/flutter (13793): Token: cOZlHYsGTKk:APA91bFsYC1DBR-Ysij14IwGienYN9Prq5JiBsvVBaVtthKAb0ZCfOxGW4cKU95IQqA3zw-BkunLe8G5wB4FLFvYDPDj_WvRLY377yNU2pX5R0N6C3vMg5xHCSfhmzJtF_16Yp5ovxfg
它无限循环
答案 0 :(得分:0)
我回答了自己的问题
我把它放在didChangeDependencies上,所以它一次又一次地调用
现在我将其放在initState上,并解决问题