Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileNotFoundError with flutter_dotenv

Tags:

flutter

dotenv

I installed flutter_dotenv with this command:

flutter pub add flutter_dotenv

My is pubspec.yaml is like:

dependencies:
  flutter:
    flutter_dotenv: ^5.0.0

flutter:
assets:
    - .env

Then I put .env file in the project root (I will use .env.dev. .env.prd later so you see them in the screen shot):

enter image description here

I run project from VSCode then get FileNotFoundError: enter image description here

I checked the .env file location hundred of times, tried to change the file name, change the location to /lib etc - still no luck. Any idea?

like image 594
ASH Avatar asked Sep 05 '25 03:09

ASH


2 Answers

I found what was wrong. "assets:" must be under "flutter:", so tab is necessary before "assets:". That's it!

flutter:
  assets:
    - .env
like image 181
ASH Avatar answered Sep 07 '25 21:09

ASH


flutter:
  assets:
    - .env

It's working for me.

like image 25
Học Thiết kế OniVn Avatar answered Sep 07 '25 19:09

Học Thiết kế OniVn