java-james / flutter_dotenv

Loads environment variables from `.env`.
https://pub.dartlang.org/packages/flutter_dotenv
MIT License
213 stars 48 forks source link

Failed to use flutter_dotenv with Android #33

Closed Gourdbaby closed 3 years ago

Gourdbaby commented 3 years ago

In my case, I am using flutter_dotenv like this.

import 'package:flutter_dotenv/flutter_dotenv.dart' as DotEnv;

Future<void> main() async {
  await DotEnv.load(fileName: ".env");
  WidgetsFlutterBinding.ensureInitialized();
  cameras = await availableCameras();
  runApp(MyApp(cameras: cameras));
}

I got a error

E/flutter (14900): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Instance of 'FileNotFoundError'

in the line for await DotEnv.load(fileName: ".env");. This is why it?

ngxingyu commented 3 years ago

Is your .env file located in the project root folder and .env added to pubspec.yaml as

flutter:
  assets:
    -.env
java-james commented 3 years ago

@Gourdbaby Thanks for the issue. Most likely the env file isn't part of the bundle. Did you tru the solution suggested above? Any luck?

java-james commented 3 years ago

@Gourdbaby have tried and cannot reproduce this issue on android - Closing the issue for now due to inactivity and suspect missing config. Please re open if the issue persists after confirming your pubspec config