Flutter 在Flatter与代码资源中使用资源时出现此错误:-资源/图像/

Flutter 在Flatter与代码资源中使用资源时出现此错误:-资源/图像/,flutter,Flutter,在Flatter与代码资源中使用资源时出现此错误:-资源/图像/ [demo] flutter pub get Error detected in pubspec.yaml: Error on line 51, column 4: Expected a key while parsing a block mapping. ╷ 51 │ assets: │ ^ ╵ Please correct the pubspec.yaml file at D:\Flutter\d

在Flatter与代码资源中使用资源时出现此错误:-资源/图像/

[demo] flutter pub get
Error detected in pubspec.yaml:
Error on line 51, column 4: Expected a key while parsing a block mapping.
   ╷
51 │    assets:
   │    ^
   ╵
Please correct the pubspec.yaml file at D:\Flutter\demo\pubspec.yaml
exit code 1

我猜您的pubspec.yaml文件中有一些语法错误

flutter:
  # To add assets to your application, add an assets section, like this:
   assets:
    - images/a_dot_burr.jpeg
    - images/a_dot_ham.jpeg
下面是一个关于如何在pubspec.yaml文件中提到资产部分的片段

flutter:
  # To add assets to your application, add an assets section, like this:
   assets:
    - images/a_dot_burr.jpeg
    - images/a_dot_ham.jpeg
现在需要将images文件夹放在主目录中,而不是lib文件夹中


希望它能解决您的问题。

Pubspec.yaml区分大小写,需要注意间距

没有空间给父对象 2儿童空间 2.给孙儿更多空间


希望它能让您理解

给我pubspec.yaml的截图,添加您的pubspec.yaml文件截图或代码看起来您在
资产之后没有添加新行:
资产:-资产/图像/#-图像/a#u dot_ham.jpeg资产:-资产/图像/#-图像/a#dot_ham.jpeg