flutter 引用图片资源遇到的问题

1.在 pubspec.yaml 引用图片资源,编译不通过

Error on line 61, column 5: Expected a key while parsing a block mapping.
   ╷
61 │     assets:
   │     ^
   ╵
Exception: Please correct the pubspec.yaml file at .\pubspec.yaml

原因:assets标签和flutter下的子标签 没有左对齐,删除空格即可 

2.加载本地图片,报 404 flutter - FlutterError: Unable to load asset 这个错误

Error while trying to load an asset: Failed to load asset at "assets/images/test.png" (404)

原因:数据bulid生成的问题

解决方法:

  • 进入当前Flutter工程的根目录,建议使用终端进入
  • 执行:flutter clean
  • 再次运行flutter项目即可

猜你喜欢

转载自blog.csdn.net/xiaowang_lj/article/details/128573135