Android Firebase消息传递:无限onLaunch循环
我已经构建了一个带有颤振的Android应用程序,并在该应用程序上集成了Firebase消息 我遇到了一个问题,如果Android设备在应用程序关闭时收到通知;该通知将无限次地启动Android Firebase消息传递:无限onLaunch循环,android,firebase-cloud-messaging,flutter,Android,Firebase Cloud Messaging,Flutter,我已经构建了一个带有颤振的Android应用程序,并在该应用程序上集成了Firebase消息 我遇到了一个问题,如果Android设备在应用程序关闭时收到通知;该通知将无限次地启动onLaunch 我打开了一个问题,但希望有人已经解决了问题(或知道原因) 我尝试过移动下面的代码,但仍然看到相同的结果。即使在设备上重新安装之后,我仍然看到这个问题 以前有人见过这个吗 @override void initState() { super.initState(); /// Navigate
onLaunch
我打开了一个问题,但希望有人已经解决了问题(或知道原因)
我尝试过移动下面的代码,但仍然看到相同的结果。即使在设备上重新安装之后,我仍然看到这个问题
以前有人见过这个吗
@override
void initState() {
super.initState();
/// Navigate to item based on message type
///
void _navigateToItemDetail(Map<String, dynamic> message) {
if (message.containsKey("type")) {
// handle messages by type
String type = message["type"];
String _id = message["_id"] ?? "";
switch (type) {
case "private_message":
Application.router.navigateTo(context, "/private_message/$_id");
break;
case "announcement":
FlutterWebBrowser.openWebPage(
url: message["url"] ?? "https://me.app",
androidToolbarColor: Colors.red
);
break;
case "public_message":
Application.router.navigateTo(context, "/public_message/$_id");
break;
default:
}
}
}
Future<Null> _showItemDialog(Map<String, dynamic> message, BuildContext ctx) async {
return showDialog<Null>(
context: ctx,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return new AlertDialog(
title: new Text(
'New Notification!',
style: new TextStyle(
fontWeight: FontWeight.w800,
)
),
content: new SingleChildScrollView(
child: new ListBody(
children: <Widget>[
new Text(message["summary"] ?? "You have a message"),
],
),
),
actions: <Widget>[
new FlatButton(
textColor: Colors.red[900],
child: new Text(
"View",
style: new TextStyle(fontFamily: "Roboto")
),
onPressed: () {
_navigateToItemDetail(message);
Navigator.pop(context);
}
),
new FlatButton(
textColor: Colors.red[900],
child: new Text('Ignore', style: new TextStyle(fontFamily: "Roboto")),
onPressed: () {
Navigator.pop(context);
},
),
],
);
},
).then((shs) {
print("$shs results");
});
}
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) {
print("onMessage: $message");
_showItemDialog(message, context);
},
onLaunch: (Map<String, dynamic> message) {
print("onLaunch: $message");
_navigateToItemDetail(message);
},
onResume: (Map<String, dynamic> message) {
print("onResume: $message");
_navigateToItemDetail(message);
},
);
}
@覆盖
void initState(){
super.initState();
///根据消息类型导航到项目
///
void _navigateToItemDetail(地图消息){
if(message.containsKey(“类型”)){
//按类型处理消息
字符串类型=消息[“类型”];
字符串_id=消息[“_id”]??”;
开关(类型){
案例“私人信息”:
Application.router.navigateTo(上下文,“/private\u message/$\u id”);
打破
案例“公告”:
webbrowser.openWebPage(
url:消息[“url”]??“https://me.app",
AndroidColor:Colors.red
);
打破
案例“公共信息”:
Application.router.navigateTo(上下文,“/public\u message/$\u id”);
打破
违约:
}
}
}
Future\u showItemDialog(映射消息,BuildContext ctx)异步{
返回显示对话框(
背景:ctx,
barrierDismissible:false,//用户必须点击按钮!
生成器:(BuildContext上下文){
返回新警报对话框(
标题:新文本(
“新通知!”,
样式:新文本样式(
fontWeight:fontWeight.w800,
)
),
内容:新建SingleChildScrollView(
child:newlistbody(
儿童:[
新文本(消息[“摘要”]?“您有消息”),
],
),
),
行动:[
新扁平按钮(
textColor:Colors.red[900],
儿童:新文本(
“视图”,
样式:新文本样式(fontFamily:“Roboto”)
),
已按下:(){
_导航项目详细信息(消息);
Navigator.pop(上下文);
}
),
新扁平按钮(
textColor:Colors.red[900],
子项:新文本(“忽略”,样式:新文本样式(fontFamily:“Roboto”),
已按下:(){
Navigator.pop(上下文);
},
),
],
);
},
).然后((shs){
打印($shs结果);
});
}
_firebaseMessaging.configure(
onMessage:(映射消息){
打印(“onMessage:$message”);
_showItemDialog(消息、上下文);
},
onLaunch:(映射消息){
打印(“onLaunch:$message”);
_导航项目详细信息(消息);
},
onResume:(映射消息){
打印(“onResume:$message”);
_导航项目详细信息(消息);
},
);
}
问题不在于Firebase消息
对于发现自己在这里的其他人:
我有一个
BottomNavigation
,它基于flatter中的演示。我导航到了相同的BottomNavigation
,这导致了一个无限的导航循环。在GitHub上回答。结果表明,我导航到了我设置Firebase配置的同一个小部件@阿瑟汤姆森把我引向了正确的方向,现在问题解决了!