【问题标题】:Flutter drawer background image颤振抽屉背景图片
【发布时间】:2019-10-30 10:07:55
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    您可以在 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);
                  },
                ),
              ],
            ),
          ),
        );
    

    也可以看到link

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2018-06-05
        • 1970-01-01
        • 2022-11-02
        • 1970-01-01
        • 1970-01-01
        • 2019-05-19
        • 2020-10-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多