flutterdartdart-define

flutter --dart-define-from-file is not working


I want to import env value from json file to my project but get this error.

Json config define file "--dart-define-from-file=config.json" is not a file, please fix first!

(https://i.sstatic.net/KX20D.png) My project literally have 2 files which is main.dart and config.json as you see in the image. I tried to replce the additional run args with

--dart-define-from-file config.json

or

--dart-define-from-file="config.json"

but none of that seems to be working.

I also tried to type it manually on terminal but got the same result. (https://i.sstatic.net/2yOZM.png)

What went wrong here?


Solution

  • You need to either move the config.json file to the root of your project, or set:

    --dart-define-from-file="lib/config.json"