这是我的pubspec.yaml文件
flutter:
# The following line ensures that the Material Icons font is
# included with your application so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/m1.jpg
- assets/m2.jpg
- assets/m3.jpg
- assets/m4.jpg
- assets/cat/m13.jpg
除上述图像外,其他图像均有效
- assets/cat/m13.jpg
我在pubspec.yaml文件中没有收到错误,并且运行“ flutter包获取”给出的退出代码为0。
在HorizontalListView.dart中,我有以下课程
class _HorizontalListViewState extends State<HorizontalListView> {
@override
Widget build(BuildContext context) {
return Container(
height: 80.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Category(
image_location: " assets/cat/m13.jpg",
image_caption: "shirts",
),
],
),
);
}
}
我面临的错误是
The following assertion was thrown resolving an image codec:
I/flutter (17029): Unable to load asset: assets/cat/m13.jpg
I/flutter (17029):
I/flutter (17029): When the exception was thrown, this was the stack:
I/flutter (17029): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter (17029): <asynchronous suspension>
I/flutter (17029): #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:484:44)
I/flutter (17029): #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:469:14)
I/flutter (17029): #3 ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
I/flutter (17029): #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
I/flutter (17029): #5 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:325:84)
I/flutter (17029): (elided 13 frames from package dart:async)
I/flutter (17029):
I/flutter (17029): Image provider: AssetImage(bundle: null, name: " assets/cat/m13.jpg")
I/flutter (17029): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#5adcb(), name: " assets/cat/m13.jpg",
预先感谢
答案 0 :(得分:2)
正确检查文件夹的名称,图像文件名和图像扩展名。我相信是否加载了除一个以外的所有其他图像。 然后
不正确:
资产:
正确:
资产:
例如:资产/cats/m13.jpg或资产/cat/m134.jpg或资产/cat/m13.png
答案 1 :(得分:0)
您在.yaml文件上的资产实施失败。应该像下面的
assets:
- assets/fuse.png
- assets/not_found.png
或实施文件夹中的所有文件;
assets:
- assets/
答案 2 :(得分:0)
解决
不正确
assets:
- assets/m1.jpg
- assets/m2.jpg
- assets/m3.jpg
- assets/m4.jpg
- assets/cat/m13.jpg
正确
assets:
- assets/m1.jpg
- assets/m2.jpg
- assets/m3.jpg
- assets/m4.jpg
- assets/cat/m13.jpg