Flutter使用go_router处理Deep Link仅获单个参数问题求助
Flutter go_router Deep Link多参数获取问题解决
问题根源:你执行adb测试命令时,URL中的&符号在Android Shell环境下会被识别为后台执行命令的分隔符,导致&name=john&email=email@example.com部分被截断,所以go_router只能接收到第一个参数。
解决办法:
- Linux/macOS Shell环境:用单引号包裹完整URL,避免Shell解析
&符号adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d 'https://example.com/play?id=1&name=john&email=email@example.com' - Windows CMD环境:用双引号包裹URL,并将
&转义为^&adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://example.com/play?id=1^&name=john^&email=email@example.com"
验证与参数获取:
修改命令后重新测试,state.uri会输出完整URL。你可以通过state.uri.queryParameters直接提取所有参数:
GoRoute( path: 'play', name: 'play', builder: (context, state) { final id = state.uri.queryParameters['id']; final name = state.uri.queryParameters['name']; final email = state.uri.queryParameters['email']; print('id: $id, name: $name, email: $email'); return const AudioPlayerScreen(); }, ),
内容的提问来源于stack exchange,提问作者shereef hamed
相关产品推荐
相关产品推荐

