[英]While adding flutter to an existing android app, How could I use a different base URL in flutter_module based on `stage`, `prod` android flavor?
I have added the flutter module in an android project, and now I want to use a different entry file for flutter based on android flavor
.我已经在 android 项目中添加了 flutter 模块,现在我想使用基于 ZC31B32364CE19CA8FCD150A417ECCE 的flavor
的不同入口文件。
like:-喜欢:-
for stage flavor: main.stage.dart舞台风格:main.stage.dart
prod flavor: main.prod.dart产品风味:main.prod.dart
is there any way to do that?有什么办法吗?
OR或者
How could I initialize environment variables in flutter based on the android flavor?如何根据 android 风格在 flutter 中初始化环境变量?
OR或者
While adding flutter to an existing android app, How could I use a different base URL in flutter_module based on stage
, prod
android flavor?在将 flutter 添加到现有的 android 应用程序时,如何在基于stage
的 flutter_module 中使用不同的基础 URL , prod
ZC31B32AFCCE100
I haven't tried but I think you could do something like this我没试过,但我认为你可以做这样的事情
Create a run configuration for each flavor and write in the Additional arguments field:为每种风味创建一个运行配置,并在Additional arguments字段中写入:
--flavor stage --dart-define=app.flavor=stage
Then in the dart side, you can retrieve the value in this way然后在dart端,可以这样取值
const String flavor = String.fromEnvironment('app.flavor');
And based on the value of the string flavor you can decide what to do.并且根据字符串风味的值,您可以决定要做什么。
if you want to build your app by console the complete command should look like this如果您想通过控制台构建您的应用程序,完整的命令应如下所示
flutter build apk/ios --flavor stage --dart-define=app.flavor=stage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.