Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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 如何将dart变量传递到index.html_Flutter_Environment Variables_Flutter Web - Fatal编程技术网

Flutter 如何将dart变量传递到index.html

Flutter 如何将dart变量传递到index.html,flutter,environment-variables,flutter-web,Flutter,Environment Variables,Flutter Web,我一直在使用Environment builds开发我的Flatter应用程序,我想根据我正在进行的web构建类型修改index.html文件 有没有办法做到这一点? 我有一个env.dart,其中包含我需要的变量,但我不知道如何使用我的dart变量修改index.html 谢谢。使用shellscript解决方案 我目前使用的是一个shell脚本 设置特定于环境的index.html 从项目文件夹创建存储index.html文件的环境: mkdir config cd config mkdir

我一直在使用Environment builds开发我的Flatter应用程序,我想根据我正在进行的web构建类型修改index.html文件

有没有办法做到这一点? 我有一个env.dart,其中包含我需要的变量,但我不知道如何使用我的dart变量修改index.html

谢谢。

使用shellscript解决方案 我目前使用的是一个shell脚本

设置特定于环境的index.html 从项目文件夹创建存储index.html文件的环境:

mkdir config
cd config
mkdir release
mkdir dev
mkdir uat
然后将不同的index.html(特别是web/)复制到config/release/config/dev/和config/uat/

cp ../web/index.html release/ && cp ../web/index.html dev/ && cp ../web/index.html uat/
/!\备份位于WEB/INDEX.HTML中的当前文件 该脚本将把index.html从不同的环境目录直接复制到web/并删除web/中的当前文件。如果您永久删除该文件,我拒绝承担任何责任。你被警告了


脚本文件 创建脚本文件:

touch run.sh && chmod +x run.sh
将此脚本复制到:

cp config/$1/index.html web/index.html&&flatter run-d chrome——无声音零安全

如何使用 并使用
/run.sh release
/run.sh dev
/run.sh dev
运行它

为特定于环境的变量使用--dart定义 我还使用
--dart define

flutter run --dart-define=MY_ENV_VARIABLE=ITS_VALUE

注意:我目前禁用了空安全性,因为我的项目的lib还不是空安全的。

这不是一个很好的答案,但当我过去需要这样做时,我已经编写了一个python构建脚本,修改html文件,然后运行我的构建命令。