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

如何将数据从Angular应用传递到Flutter应用?URL传参无法接收

问题修复方案

已知错误点

  • URL拼接语法错误:Angular端字符串拼接逻辑混乱,实际生成的URL没有正确带入Value1变量值,反而会把拼接符号当成URL的一部分
  • URL格式错误:路径与查询参数之间存在多余空格,会导致URI解析异常
  • 参数名不匹配:Angular端传递的参数名为InputParameter1,Flutter端取值时用的参数名为InputParameter,二者不一致
  • 哈希路由参数解析错误:Flutter Web使用哈希路由模式时,查询参数放在#标识的路由片段后,直接解析整个href的queryParameters会取不到哈希片段内的参数

修复后的代码

Angular端代码

import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})

export class AppComponent {
title = 'web-app';
onNavigate(){
  // 正确拼接URL,参数值做编码处理,去掉多余空格
  const Value1 = "你要传递的实际值";
  const url = `http://localhost:61097/#/plants/garden?InputParameter1=${encodeURIComponent(Value1)}`;
  window.open(url, '_blank');   
}
}

Flutter端代码

import 'dart:html' as html;

void get() {
  // 先提取哈希路由片段,去掉开头的#号后再解析参数
  final hashFragment = html.window.location.hash.substring(1);
  final uri = Uri.parse(hashFragment);
  final Map<String, String> params = uri.queryParameters;
  String? data = params["InputParameter1"]; // 参数名和Angular端保持一致
}

验证方式

打开跳转后的Flutter页面,直接查看浏览器地址栏的URL,确认参数是否正确拼接在路由后面,再打印data变量即可确认取值结果。

内容的提问来源于stack exchange,提问作者Pragati Gawande

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 23:30:02