Environment variables #1982
-
If you are looking for help, please confirm the following...
Which mobile framework are you using?Flutter (Dart) Steps to reproduceIf i want to use SHA-256 certificates in the dart code but i don't want them to be on the repository. Expected resultsHow to create environment variables and access it inside the dart code? Actual resultsI don't know how to access environment variables inside the dart code. Build id (optional)No response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello @AbanoubZaki Dart has different ways of using environment variables. One way to do it would be like this:
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 me know if manage to get everything configured to your needs. If issues occur, let me know. |
Beta Was this translation helpful? Give feedback.
Hello @AbanoubZaki
Dart has different ways of using environment variables.
One way to do it would be like this:
--dart-define
to your scripts. E.gflutter build apk --dart-define=API_KEY=$CM_TESTENV1 --dart-define=SOMEOTHERVAR=$CM_TESTENV2
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 …