如何在点击通知时转到特定屏幕?我在javascript中使用了云功能,当我单击通知时,它打开了我的应用程序而不是特定的屏幕
LoadError: MethodError: Cannot `convert` an object of type HTMLText to an object of type Int64
答案 0 :(得分:1)
您可以尝试使用命名的路线+全局导航键,它在稍微不同的情况下对我有用。
首先像这样设置全局导航键:
A count
3 c 0
---------------
A count
9 a 2
---------------
A count
0 c 3
2 b 3
---------------
A count
1 b 4
5 d 4
6 a 4
7 b 4
---------------
A count
8 c 5
---------------
A count
4 d 8
---------------
然后在下面定义命名的路由管理器:
...
class MyApp extends StatelessWidget {
static final navigatorKey = GlobalKey<NavigatorState>();
...
并将navigatorKey和路由添加到MaterialApp:
...
Route routes(RouteSettings settings) {
if (settings.name == "/") {
return MaterialPageRoute(
builder: (_) => HomePage(),
);
} else if (settings.name.startsWith("/details/")) {
try {
String id = settings.name.split("/")[2];
return MaterialPageRoute(
builder: (_) => DetailPage(id),
);
} catch (e) {
return MaterialPageRoute(
builder: (_) => HomePage(),
);
}
} else {
return MaterialPageRoute(
builder: (_) => HomePage(),
);
}
}
...
完成所有这些设置后,您可以使用导航键在首页和详细信息之间导航,如下所示:
...
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: "/",
onGenerateRoute: routes,
title: 'MyApp',
navigatorKey: navigatorKey,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
...
希望它有用,祝你好运!