简体   繁体   English

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?

[英]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
  • The first command is for telling the build command which flavor it is going to build.第一个命令用于告诉构建命令它将构建哪种风味。
  • The second command is for creating a variable that you will retrieve later in the dart side第二个命令用于创建一个变量,稍后您将在 dart 端检索该变量

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.

相关问题 将 flutter 模块添加到现有的 android 工作室应用程序 - adding flutter module to existing android studio app 在现有的Android应用程序中集成Flutter模块时出现问题 - Problem integrating flutter module in existing android app 为每个 android 风格使用不同的库模块 - Use different library module for each android flavor 如何根据两种不同的风味尺寸设置我的Android应用包名称? - How do I set my Android app package name based on two different flavor dimensions? 如何将 Flutter 添加到现有或新的 Android 应用程序 - How Add Flutter To Existing Or New Android App Flutter-Android如何在应用程序处于前台/后台时使用相机 - Flutter-Android how to use the camera while the app is in foreground/background 如何在android的build.gradle文件中定义flutter应用程序的基本URL? - How to define base URL for flutter app in build.gradle file of android? 在android应用程序中集成flutter模块时出现绑定错误 - Binding error while integrating flutter module in android app 如何用 Flutter 应用替换现有的原生 Android/iOS 应用? - How to replace existing native Android/iOS app with Flutter app? 如何在flutter上使用android的app bundle? - How to use app bundle of android on flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM