Search code examples
androidgradledartflutterbuildconfig

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.

I'm using Gradle to generated some of the constants I need in my code.

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.

I was able to write down a constant in first of BuildConfig, problem is, I cannot refer to it from my code.

What am I missing or doing wrong?


Solution

  • Flutter is not Android. BuildConfig has nothing to do with dart code.

    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.

    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.

    This way, you can instantiate a custom InheritedWidget that pass down configurations with different values depending on your build target.