试图以抖动方式加载图像,但无法执行此操作,出现以下错误
I / flutter(3214):BY图像资源服务引起的异常提示 ╞═════════════════════════════════════════════════ ═══我/颤振( 3214):抛出了以下断言来解析图像编解码器: I / flutter(3214):无法加载资产:assets / test.jpg I / flutter( 3214):I / flutter(3214):引发异常时,这是 堆栈:I / flutter(3214):#0 PlatformAssetBundle.load (package:flutter / src / services / asset_bundle.dart:221:7)I / flutter( 3214):I / flutter(3214):#1
AssetBundleImageProvider._loadAsync (package:flutter / src / painting / image_provider.dart:429:44)I / flutter( 3214):I / flutter(3214):#2
AssetBundleImageProvider.load (包:flutter / src / painting / image_provider.dart:414:14)I / flutter( 3214):#3 ImageProvider.resolve ..(package:flutter / src / painting / image_provider.dart:267:86) I / flutter(3214):#4 ImageCache.putIfAbsent (package:flutter / src / painting / image_cache.dart:143:20)I / flutter( 3214):#5 ImageProvider.resolve。 (包:flutter / src / painting / image_provider.dart:267:63)I / flutter( 3214):(从dart:async包中删除了8帧)I / flutter(3214): I / flutter(3214):图片提供者:AssetImage(捆绑:null,名称: “ assets / test.jpg”)I / flutter(3214):图片键: AssetBundleImageKey(bundle:PlatformAssetBundle#81de5(),名称: “ assets / test.jpg”,比例尺:I / flutter(3214):1.0)I / flutter(3214):
main.dart
lass MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('EasyList'),
),
body: Card(child: Column(children: < Widget > [
Image.asset('assets/test.jpg'),
],),),
),
);
}
}
pubspec.yaml
flutter:
uses-material-design: true
assets:
- assets/test.jpg
答案 0 :(得分:3)
在单词assets:
前面需要两个空格,在破折号之前需要两个附加空格(总共4个)。
flutter:
uses-material-design: true
assets:
- assets/test.jpg
答案 1 :(得分:1)
或者如果您正在使用Android Studio IDE,则只需在pubspec.yaml
文件中按
CTRL + ALT + L 重新排列代码。然后单击包获取。