[Add to app] android: Unhandled Exception: Instance of 'FileNotFoundError'
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>
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.
any updates for this issue?
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(),
);
}
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
Some issue, I fix add this: await dotenv.load(fileName: "config.env");
assets:
- config.env