Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFoundError #72

Open
jerinho opened this issue Sep 14, 2022 · 6 comments
Open

FileNotFoundError #72

jerinho opened this issue Sep 14, 2022 · 6 comments

Comments

@jerinho
Copy link

jerinho commented Sep 14, 2022

E/flutter (29283): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Instance of 'FileNotFoundError'
E/flutter (29283): #0 DotEnv._getEntriesFromFile (package:flutter_dotenv/src/dotenv.dart:98:7)
E/flutter (29283):
E/flutter (29283): #1 DotEnv.load (package:flutter_dotenv/src/dotenv.dart:65:27)
E/flutter (29283):
E/flutter (29283): #2 main (package:menu/main.dart:12:3)
E/flutter (29283):
E/flutter (29283):

@aatmmr
Copy link

aatmmr commented Nov 8, 2022

@jerinho, have you added the reference to your .env file to the pubspec.yaml? Make sure the reference is located, such as,

flutter:
  [...]

  assets:
  - .env

where assets is in the flutter section.

Otherwise, check if your name is other than .env and if so, that the initialisation specifies the fileName, such as,

await dotenv.load(fileName: ".env.yourName");

I hope that helps.

@fleeser
Copy link

fleeser commented Dec 3, 2022

You probably put the .env file inside of the lib folder. Instead, you should put it into the root directory one layer above.

@bleszerd
Copy link

bleszerd commented Jan 18, 2023

I have the same problem.

Project structure

image

.env

TWITTER_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXX
TWITTER_API_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter

  #...
  flutter_dotenv: ^5.0.2
  #...

  assets:
    - assets/icons/
    - .env

main.dart

WidgetsFlutterBinding.ensureInitialized();
DartPluginRegistrant.ensureInitialized();

await dotenv.load(
  fileName: ".env",
);

runApp(
  StoreProvider(
    store: appStore,
    child: const MyAppName(),
  ),
);

flutter_build_android_31.log

A curious fact is that I ran the exact same code a few days ago on Linux and it worked, just like when I came to Windows. As much as I believe this did not influence, I thought it best to say this.

@KevinVegaRem
Copy link

Some issue, I fix add this:
await dotenv.load(fileName: "config.env");

assets:
- config.env

@ferrarafer
Copy link

ferrarafer commented Apr 4, 2023

This issue in general is because the .env file is empty. I wasted a huge amount of time until I realize this. The error should be different or should be no error on empty files.

I think this behavior could be different depending on the operative system. I made my tests on macOS Ventura using flutter web.

@gargashwani
Copy link

I have the same problem.

Project structure

image

.env

TWITTER_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXX
TWITTER_API_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter

  #...
  flutter_dotenv: ^5.0.2
  #...

  assets:
    - assets/icons/
    - .env

main.dart

WidgetsFlutterBinding.ensureInitialized();
DartPluginRegistrant.ensureInitialized();

await dotenv.load(
  fileName: ".env",
);

runApp(
  StoreProvider(
    store: appStore,
    child: const MyAppName(),
  ),
);

flutter_build_android_31.log

A curious fact is that I ran the exact same code a few days ago on Linux and it worked, just like when I came to Windows. As much as I believe this did not influence, I thought it best to say this.

Saved Much Time.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants