[英]BuildConfig (or alternative) in Flutter
I'm new in Flutter and I'm looking for something similar to generated BuildConfig class I know from classic Android development. 我是Flutter的新手,我正在寻找类似于生成的BuildConfig类的东西,我从经典的Android开发中知道。
I'm using Gradle to generated some of the constants I need in my code. 我正在使用Gradle在代码中生成一些我需要的常量。
I could find 2 BuildConfig files in my project, one in project/build/app/generated/source/buildConfig/projectName/BuildConfig.java
and other one in library called shared_preferences-0.2.5/android/build/intermediates/classes/debug.io.flutter.plugins.sharedpreferences/BuildConfig.java
. 我可以在我的项目中找到2个BuildConfig文件,一个在
project/build/app/generated/source/buildConfig/projectName/BuildConfig.java
,另一个在库中名为shared_preferences-0.2.5/android/build/intermediates/classes/debug.io.flutter.plugins.sharedpreferences/BuildConfig.java
。
I was able to write down a constant in first of BuildConfig , problem is, I cannot refer to it from my code. 我能够在BuildConfig的第一个中写下一个常量,问题是,我不能从我的代码中引用它。
What am I missing or doing wrong? 我错过了什么或做错了什么?
Flutter is not Android. 颤动不是Android。 BuildConfig has nothing to do with dart code.
BuildConfig与dart代码无关。
So far, there's no such thing in flutter. 到目前为止,没有这样的事情在颤动。 What we currently do instead is having a different
main.dart
depending on the build mode. 我们目前所做的是根据构建模式使用不同的
main.dart
。
For that you'll simply do flutter build apk --release -t lib/main.release.dart
which will define lib/main.release.dart
as your entry point to the application. 为此你只需要做
flutter build apk --release -t lib/main.release.dart
,它将定义lib/main.release.dart
作为你的应用程序的入口点。
This way, you can instantiate a custom InheritedWidget
that pass down configurations with different values depending on your build target. 这样,您可以实例化一个自定义的
InheritedWidget
,它根据您的构建目标传递具有不同值的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.