Closed qcuong96 closed 3 years ago
Hi thanks for creating the issue. Have you defined .env as an asset to bundle in the pubspec?
Add the .env file to your assets bundle in pubspec.yaml
assets:
- .env
What version of flutter are you using?
Hi thanks for creating the issue. Have you defined .env as an asset to bundle in the pubspec?
Add the .env file to your assets bundle in pubspec.yaml assets: - .env
What version of flutter are you using?
version: 1.0.0+1
environment: sdk: ">=2.7.0 <3.0.0"
dependencies: http: ^0.12.2 flutter: sdk: flutter
Already added .env
Facing the same issue.
Hi again, it is working perfectly fine. My mistake was I had created the .env
file in the lib
directory. Instead it needs to be outside of lib
in the root of the project. @qcuong96, verify that you are not making the same mistake.
Hi again, it is working perfectly fine. My mistake was I had created the
.env
file in thelib
directory. Instead it needs to be outside oflib
in the root of the project. @qcuong96, verify that you are not making the same mistake.
I have tried outside the lib, in the root. still its not working
For the record (don't know why) but with version 1.20 of Flutter loaded assets can't be in the root dir and must be inside a folder, for example assets folder. I was a experiencing a similar issue and moving the dotenv file inside the assets folder make the trick for me. Also remember that now the load()
method should have the path too.
Ex.: await DotEnv().load('assets/.env');
Hope it helps
Thanks for this @hazzo I will try this out and confirm the issue then update the usage docs accordingly
For the record (don't know why) but with version 1.20 of Flutter loaded assets can't be in the root dir and must be inside a folder, for example assets folder. I was a experiencing a similar issue and moving the dotenv file inside de de assets folder make the trick for me. Also remember that now the
load()
method should have the path too. Ex.:await DotEnv().load('assets/.env');
Hope it helps
Running on 1.22 on root folder whatsoever
I'm having the same issue. I've tried having .env in root as well as an assets folder (with the appropriate changes to pubspec.yaml and the load method). It also gives the same empty object/map if I don't have an .env file at all, though. I did make sure to stop and rebuild between all changes, not just hot reload. Is there anything cached in the build files that could be causing it? I'm very new to flutter and gradle.
Flutter 1.20.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision 216dee60c0 (6 days ago) • 2020-09-01 12:24:47 -0700 Engine • revision d1bc06f032 Tools • Dart 2.9.2
To me is the same as @hazzo , only works with .env in assets folder, would like to have in the root. Flutter version 1.22.0
It works fine guys. I guess that you're not putting all pieces together correctly.
First of all I would guess that you're misplacing assets
in the pubspec.yaml. It has to go like flutter: > assets: > - .env
into structure. Then it doesn't matter if you call DotEnv().load('.env')
or DotEnv().load()
Both pubspec.yaml
and lib/main.dart
has to be in sync. Assets has to be set and placed correctly.
For the record (don't know why) but with version 1.20 of Flutter loaded assets can't be in the root dir and must be inside a folder, for example assets folder. I was a experiencing a similar issue and moving the dotenv file inside de de assets folder make the trick for me. Also remember that now the
load()
method should have the path too. Ex.:await DotEnv().load('assets/.env');
Hope it helps
Had the same issue, and this worked for me
Have verified working in root on latest flutter. Thanks for the reply @Must4che. Suggest reading his comment above if you are experiencing this issue.
have clarified some instructions in 3.0.0. Please reopen if this is still an issue in the latest release.
I try to use this lib by add in the main function and print to test it. However the result is empty even I define something in .env file This is the main.dart
This is the .env file