【问题标题】:Unable to load Image in Drawer header无法在抽屉标题中加载图像
【发布时间】:2020-03-26 21:48:08
【问题描述】:

在我的颤振应用程序中,我无法在抽屉标题中加载图像。 我已经用了好几个小时了,不明白为什么它不起作用。

有什么问题

请帮忙

Container(
  width: 100,
  height: 100,
  child: UserAccountsDrawerHeader(
    accountName: const Text(_AccountName),
    accountEmail: const Text(_AccountEmail),
    currentAccountPicture: CircleAvatar(
      backgroundColor: Colors.brown,
      child: Text(_AccountAbbr),
    ),
    decoration: BoxDecoration(
    //color: Colors.yellow,
    image: DecorationImage(
      image: AssetImage('../assets/md_drawer_header.png'),
      fit: BoxFit.cover,
      ),
    ),
  ),
),

【问题讨论】:

  • 你的pubspec.yaml是什么样的?
  • 我没有对 pubspec.yaml 进行任何更改 -
  • dependencies: flutter: sdk: flutter dev_dependencies: flutter_test: sdk: flutter
  • 你加载你的资产了吗?
  • 你是什么意思?

标签: android iphone flutter dart


【解决方案1】:

第1步:请删除路径中的../

代码sn-p

image: DecorationImage(
      image: AssetImage('assets/md_drawer_header.png'),
      fit: BoxFit.cover,
      ),
    ),

第二步:不要把图片放到lib文件夹中,你可以在lib同级创建一个文件夹assets

第 3 步:在 pubspec.yaml 中设置

assets:
  - assets/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 2016-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    相关资源
    最近更新 更多