Flutter 抽屉背景图片

Flutter drawer background image

我想知道我是否可以在 flutter 应用程序抽屉中使用背景图像而不是颜色header,有什么办法吗?

我可以自定义他的颜色,但我想知道是否有 属性 可以用自定义图像改变颜色。

您可以在 DrawerHeader 中使用修饰将图像设置为抽屉 header

  return Scaffold(
      appBar: AppBar(title: Text(title)),
      body: Center(child: Text('some text')),
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              child: Text('Drawer Header'),
              decoration: BoxDecoration(
                color: Colors.blue,
                image: DecorationImage(
                  image: AssetImage("assets/gold.jpg"),
                     fit: BoxFit.cover)
              ),
            ),
            ListTile(
              title: Text('Item 1'),
              onTap: () {
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: Text('Item 2'),
              onTap: () {
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
    );

也看到这个link

在其中声明一个容器。这对我有用:

Drawer(
    elevation: 5,
    child: Container(
      width: 200,
      height: 100,
      decoration: BoxDecoration(
        image: new DecorationImage(
          image: AssetImage("lib/assets/bookcover.jpg"),
          fit: BoxFit.cover,
        ),
      ),