一尘不染

Flutter资产错误:影像资源服务异常

flutter

颤振找不到我的图像资产,我该怎么办?

我在调试器上收到错误:

在XT1097上以调试模式启动lib / main.dart …构建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:

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('dibmartins@gmail.com'),
                    currentAccountPicture: new GestureDetector(
                        onTap: () => print('Toque na imagem'),
                        child: new CircleAvatar(
                            backgroundImage: AssetImage('assets/images/user/avatar.png'),
                        )
                    )
                ),

阅读 290

收藏
2020-08-13

共1个答案

一尘不染

据我所知,目前仅将直接位于注册目录下的文件添加到资产中。

这应该工作:

flutter:
  uses-material-design: true
  assets:
   - assets/images/
   - assets/images/user/
2020-08-13