小编WXM*_*967的帖子

使用 ModalRoute 检索参数时出错

每次调用 modalroute 从命名路由检索参数时,我都会得到 null。

\n\n

这是代码片段:

\n\n
Navigator.pushNamed(\n           context, \n           VerifyCode.routeName, \n           arguments: {\'code\': randValue,},\n           );\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我检索参数的地方:

\n\n
Widget build(BuildContext context) \n{\n   //Get the dialog provider to display information\n   alertViewModel = Provider.of<AlertViewModel>(context);\n\n   //Retrieve the route argument\n   final routeArgs =\n           ModalRoute.of(context).settings.arguments as Map<String, int>;\n\n    final securityCode = routeArgs[\'code\']; <-- Error happens here\n\n    print(\'Code =\' + securityCode.toString());\n   return Container()\n
Run Code Online (Sandbox Code Playgroud)\n\n

}

\n\n

我应该从地图中获取一个整数,但我收到了错误:

\n\n
 \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90 Exception Caught By widgets library \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following NoSuchMethodError was thrown building VerifyCode(dirty, dependencies: [InheritedProvider<AlertViewModel>, _ModalScopeStatus], state: …
Run Code Online (Sandbox Code Playgroud)

dart flutter

8
推荐指数
2
解决办法
8450
查看次数

标签 统计

dart ×1

flutter ×1