Skip to content
Discussion options

You must be logged in to vote

Hello @AbanoubZaki

Dart has different ways of using environment variables.

One way to do it would be like this:

  • Add your environment variables to Codemagic (for example, CM_TESTENV1, CM_TESTENV2)
  • When building the flutter app, add --dart-define to your scripts. E.g flutter build apk --dart-define=API_KEY=$CM_TESTENV1 --dart-define=SOMEOTHERVAR=$CM_TESTENV2
  • You can now access these variables in your code with String.fromEnvironment method. Example: String.fromEnvironment('API_KEY')

Refer to this article, which provides multiple ways of dealing with environment variables in Flutter. The aforementioned described method is one of the proposed ways in the article, a relatively easy one.

Let …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ntfnd404
Comment options

@truszko1
Comment options

@CedricBaijot
Comment options

Answer selected by AbanoubZaki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants