English 中文(简体)
纽约总部
原标题:dotenv: Unhandled Exception: Instance of FileNotFoundError
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await dotenv.load(fileName: "./env");
  var documentsDirectory =
      await path_provider.getApplicationDocumentsDirectory();

  Hive.init(documentsDirectory.path);
  Hive.registerAdapter(UserDataModelAdapter());
  Hive.registerAdapter(TaskHiveModelAdapter());

  runApp(const MyApp());
}

My file directory: enter image description here

1. 建造错误:

No file or variants found for asset: .env.
Error detected in pubspec.yaml:

Target debug_android_application failed: Exception: Failed to bundle asset files.


FAILURE: Build failed with an exception.

我在《共和国报》中设立了。 yam:

  • assets:
    • .env

怎样才能在启动时找到 Flu子吗?

最佳回答

1. 导言 <代码>相关路径可能会引起问题,你可以尝试使用一条绝对途径进入<代码>.env文档。

await dotenv.load(fileName:  /full/path/to/your/project/.env );

页: 1

await dotenv.load(fileName:  env );

2. 检查<代码>pubspec.yaml 资产中载有<代码>.env文档。

 flutter:
  assets:
    - .env

3. 。 确保档案许可:

Make sure that you have read access to the .env file. 
问题回答

暂无回答




相关问题
Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

Moving the icon button to the right causes rendering issues

I am trying to align the icon button to the right of the Text field, I tried the row which made the icon button not centered vertically and now I am trying out the Stack widget. Here is my code - ...

热门标签