无法在抽屉中加载图像 header

Unable to load Image in Drawer header

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

有什么问题

请帮忙

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,
      ),
    ),
  ),
),

第 1 步:请删除路径

中的 ../

代码片段

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

第二步:不要把图片放在lib文件夹里,可以在lib

同级新建一个文件夹assets

第 3 步:在 pubspec.yaml 中设置

assets:
  - assets/