flutter_dotenv icon indicating copy to clipboard operation
flutter_dotenv copied to clipboard

[Add to app] android: Unhandled Exception: Instance of 'FileNotFoundError'

Open kimmy-wang opened this issue 3 years ago • 6 comments

2022-05-19 21:10:06.868 6663-6703/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Instance of 'FileNotFoundError'
    #0      DotEnv._getEntriesFromFile (package:flutter_dotenv/src/dotenv.dart:98:7)
    <asynchronous suspension>
    #1      DotEnv.load (package:flutter_dotenv/src/dotenv.dart:65:27)
    <asynchronous suspension>
    #2      loadEnv (package:meetu_module/main.dart:118:5)
    <asynchronous suspension>
    #3      main (package:meetu_module/main.dart:52:3)
    <asynchronous suspension>

kimmy-wang avatar May 19 '22 13:05 kimmy-wang

Hello, I had the same problem.

To solve it, it is necessary to import the external files, to your pubspec.yaml, in the assets section:

assets: - .env

done that, you can import the load in the file in your main function:

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

Hope this helps!

It doesn't work for me.

kimmy-wang avatar May 23 '22 13:05 kimmy-wang

any updates for this issue?

ahmdmau avatar May 31 '22 07:05 ahmdmau

Same for me, Only when app is builded, then after a reload its works. Testing on a android emulator here is my main func:

Future<void> main() async {
  initializeDateFormatting('pt_BR', null);

  WidgetsFlutterBinding.ensureInitialized();

  await dotenv.load(fileName: '.env');

  BlocOverrides.runZoned(
    () {
      runApp(const MyApp());
    },
    blocObserver: LogObserver(),
  );
}

Apostata avatar Jun 03 '22 18:06 Apostata

I had the same problem.

The only way to make it work was to rename the .env file and remove the dot.

This works

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await dotenv.load(fileName: 'env.module');

  runApp(const MyApp());
}

To make it clear: this is only an Add-to-app problem (integrating a Flutter module in an existing Android/iOS app). It works flawless in a normal Flutter project

giovannilattanziocrispy avatar Jul 15 '22 07:07 giovannilattanziocrispy

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

assets:

  • config.env

KevinVegaRem avatar Jan 31 '23 23:01 KevinVegaRem