本文介绍了Flutter资产错误:影像资源服务异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
flutter找不到我的图像资产,我该怎么办?
flutter can not find my images assets, what can I be doing wrong?
调试器出现错误:
在XT1097上以调试模式启动lib / main.dart ...
构建build / app / outputs / apk / debug / app-debug.apk。
Launching lib/main.dart on XT1097 in debug mode...Built build/app/outputs/apk/debug/app-debug.apk.
I/flutter ( 876): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞══
I/flutter ( 876): Unable to load asset: assets/images/user/background.jpg
I/flutter ( 876): "assets/images/user/background.jpg", scale: 1.0)
我的pubspec.yml:
My pubspec.yml:
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
sqflite: any
path_provider: '>=0.3.0'
charts_flutter: any
cupertino_icons: ^0.1.2
material_search: ^0.2.8
dio: ^1.0.3
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/images/
和代码:
new UserAccountsDrawerHeader(
decoration : BoxDecoration(
image: new DecorationImage(
image: AssetImage('assets/images/user/background.jpg'),
fit: BoxFit.cover
),
color: Colors.blue,
),
accountName: new Text('Diego Botelho'),
accountEmail: new Text('[email protected]'),
currentAccountPicture: new GestureDetector(
onTap: () => print('Toque na imagem'),
child: new CircleAvatar(
backgroundImage: AssetImage('assets/images/user/avatar.png'),
)
)
),
推荐答案
据我所知仅将直接放置在注册目录下的文件添加到资产中。
As far as I know currently only files directly placed under the registered directory are added to assets.
这应该起作用:
flutter:
uses-material-design: true
assets:
- assets/images/
- assets/images/user/
这篇关于Flutter资产错误:影像资源服务异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!