扑抽屉背景图像

时间:2019-06-16 16:33:07

标签: flutter flutter-layout flutter-navigation flutter-appbar flutter-image

我想知道我是否可以在颤抖的应用程序抽屉标题中使用背景图像来代替颜色,有什么办法吗?

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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

  return Scaffold(
      appBar: AppBar(title: Text(title)),
      body: Center(child: Text('some text')),
      drawer: Drawer(
        // Add a ListView to the drawer. This ensures the user can scroll
        // through the options in the drawer if there isn't enough vertical
        // space to fit everything.
        child: ListView(
          // Important: Remove any padding from the 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: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: Text('Item 2'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
    );

另请参阅此link

enter image description here