Flutter抽屉背景图片

7

我想知道在Flutter应用程序抽屉头部中是否可以使用背景图像代替颜色,有什么方法吗?

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

2个回答

21

您可以在 DrawerHeader 中使用装饰来设置图像作为抽屉标题

  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);
              },
            ),
          ],
        ),
      ),
    );

另请参阅此链接

在此输入图片描述


2

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接