You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 15:52:35