Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何将参数发送到嵌入式颤振web应用程序?_Flutter_Flutter Web - Fatal编程技术网

Flutter 如何将参数发送到嵌入式颤振web应用程序?

Flutter 如何将参数发送到嵌入式颤振web应用程序?,flutter,flutter-web,Flutter,Flutter Web,按照说明,可以通过将颤振web应用程序包装到iframe元素中,将其嵌入网页,例如: <iframe src="URL"></iframe> 其中URL指向Flatter web应用程序的html 现在,如果您想根据上下文预先配置Flatter web应用程序,该怎么办?让它知道嵌入程序中存在的一些外部值(iframe HTML元素或父网页/窗口) 是否有一种解决方案可以指示flifter从iframe读取数据属性?例如: <iframe src="URL"

按照说明,可以通过将颤振web应用程序包装到iframe元素中,将其嵌入网页,例如:

<iframe src="URL"></iframe>

其中URL指向Flatter web应用程序的html

现在,如果您想根据上下文预先配置Flatter web应用程序,该怎么办?让它知道嵌入程序中存在的一些外部值(iframe HTML元素或父网页/窗口)

是否有一种解决方案可以指示flifter从iframe读取数据属性?例如:

<iframe src="URL" data-answer="42"></iframe>

还有别的选择吗


(一个更广泛的问题是可嵌入程序和嵌入程序之间的双向通信。)

设法找到了一种发送参数的方法。基本上可以在iframe的src URL上放置URL查询参数,如下所示:

<iframe src="https://foo.bar?answer=42"></iframe>

要在Flatter web应用程序中获取查询参数,您需要:

// Use a dependency on package:universal_html/html.dart
final Map<String, String> params = Uri.parse(html.window.location.href).queryParameters;
final String answer = params['answer']; // -> and there you have the "42".
//对包使用依赖项:universal\u html/html.dart
最终映射参数=Uri.parse(html.window.location.href).queryParameters;
最终字符串答案=参数['answer'];//->这就是“42”。