找不到设置为参数 "image" 的文件 "assets/background.png"。酒吧结束,退出代码为 1

The file "assets/background.png" set as the parameter "image" was not found. pub finished with exit code 1

我正在尝试使用 flutter_native_splash 1.3.1 包创建启动画面。我在 lib 文件夹中创建了一个名为 'assets' 的文件夹,并将该图像添加到该文件夹​​中。但是当我在命令行中 运行 'flutter pub run flutter_native_splash:create' 时,我得到了问题中提到的错误。

我按照包文档的建议在 pubspec.yaml 中添加了以下行。

flutter_native_splash:
  color: "#000000"
  image: assets/background.png

有人可以解释一下我可能遗漏了什么吗?

执行以下步骤

  1. 在pubspec.yaml
  2. 中添加flutter_native_splash:^1.3.1
  3. 在与 pubspec.yaml
  4. 相同级别的项目根目录中创建 flutter_native_splash.yaml
  5. 在上述文件中添加以下内容

flutter_native_splash:

color: "#000000"
image: assets/background.png
  1. 运行终端中的这个命令

flutter 酒吧 运行 flutter_native_splash:create

  1. 通过上述步骤,启动画面将正确加载,但可能会出现您提到的错误。要删除该错误,请启用 pubspec.yaml
  2. 中的以下部分

资产:

- assets/background.png

6.Make 确定你在项目的根目录中有资产目录并且 background.png 存在于其中。

7.Clean 并构建。它应该可以正常工作

继续Ehtesham Siddiquie回答。 我认为assets文件夹应该在项目的根目录下(与pubspec.yaml和flutter_native_splash.yaml同级)。但是你在 lib 文件夹中创建了它。