图像资源服务捕获到异常 运行以下代码时出现错误。
代码:
import 'package:flutter/material.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('PITCH'),
),
body: Column(
children: <Widget>[
new Text('WELCOME'),
new Image(image: AssetImage('download.png'))
],
),
),
);
}
}
错误:
颤振:IM图像资源服务引起的异常CA ═════════════════ 抖动:抛出以下断言来解析图像编解码器: 颤动:无法加载资产:download.png 扑: 扑:引发异常时,这是堆栈: 颤抖:#0 PlatformAssetBundle.load(包:flutter / src / services / asset_bundle.dart:221:7) 扑: 颤抖:#1 AssetBundleImageProvider._loadAsync(package:flutter / src / painting / image_provider.dart:464:44) 扑: 颤动:#2 AssetBundleImageProvider.load(包:flutter / src / painting / image_provider.dart:449:14) 颤动:#3 ImageProvider.resolve ...(包:flutter / src / painting / image_provider.dart:316:48) 颤动:#4 ImageCache.putIfAbsent(包:flutter / src / painting / image_cache.dart:160:22) 颤动:#5 ImageProvider.resolve ..(包:flutter / src / painting / image_provider.dart:316:25) 抖动:(从dart:async包中删除了13帧) 扑: flutter:图片提供者:AssetImage(捆绑:null,名称:“ download.png”) 颤动:图像键:AssetBundleImageKey(束:PlatformAssetBundle#ea200(),名称:“ download.png”,比例尺: 颤动:1.0)
答案 0 :(得分:2)
这可能是由于以下原因。
您忘记将资产添加到pubspec.yaml
文件中
您忘记运行flutter packages get
命令。
您已热重启/重新加载了该应用。
答案 1 :(得分:0)
确保以下几点:
flutter pub get
。'assets/download.png'