Why does the .env file get added to build/web/assets?

1.2k Views Asked by At

I'm using flutter_dotenv to manage some API keys - https://pub.dev/packages/flutter_dotenv

According to the instructions I should add the .env file to assets in pubspec.yaml but when I run flutter build web it adds the .env file to the build for deployment. This doesn't seem correct to me because the .env file should not get deployed anywhere publicly from what I understand.

2

There are 2 best solutions below

0
Tom On

I had the same issue, and solved it by renaming .env.* files to env.*.

https://pub.dev/packages/flutter_dotenv#usage

Note: If deploying to web server, ensure that the config file is uploaded and not ignored. (Whitelist the config file on the server, or name the config file without a leading .)

1
Eric Haertel On

I had same problems too. What I misunderstood from documentation, the 'assets' section is a child of the 'flutter' section in the pubspec.yml file.

So, it should look like:

flutter:
    assets:
        - .env