【问题标题】:How do I change the height of the DrawerHeader in flutter?如何在颤动中更改 DrawerHeader 的高度?
【发布时间】:2020-07-17 11:45:41
【问题描述】:

我想更改抽屉标题的高度。我在抽屉的帮助下创建了一个侧栏,但无法更改抽屉标题的高度。

我是 Flutter 开发的新手。

我试过这段代码,

drawer: Container(
        child: ClipRRect(
          borderRadius: BorderRadius.only(
              topRight: Radius.circular(30), bottomRight: Radius.circular(30)),
          child: Drawer(
            child: ListView(
              padding: EdgeInsets.only(
                top: 0.0,
              ),
              scrollDirection: Axis.vertical,
              children: <Widget>[
                DrawerHeader(
                  child: Text('data '),
                  decoration: BoxDecoration(color: Colors.green),
                ),
                ListTile(
                  title: Text('Home'),
                  leading: Icon(Icons.home, color: Colors.red),
                  
                ),
              ],
            ),
          ),
        ),
      ),

【问题讨论】:

    标签: flutter drawer


    【解决方案1】:

    你可以在这里做两件事:

    使用SizedBox 或者您可以使用自定义的Container 代替DrawerHeader

    SizedBox(
      height: 150.0,
      child: DrawerHeader(
        //add further code here
      ),
    ),
    
    //OR YOU CAN DO THIS
    
    Drawer(
      child: ListView(
        children: [
          Container(
            height: 150.0,
            child: //add futher code here
          ),
        ],
      ),
    )
    

    【讨论】:

    • 我使用了您的第二个选项container,但这样做后我无法修复我的列表视图
    • 修复列表视图是什么意思?这是关于修复标题并仅移动其下方的内容吗?
    【解决方案2】:

    DrawerHeader上方添加SizeBox

         SizedBox(
                  height: 100,
                  child: DrawerHeader(
                    child: Text('data '),
                    decoration: BoxDecoration(color: Colors.green),
                  ),
                ),
    

    【讨论】:

      猜你喜欢
      • 2020-12-29
      • 1970-01-01
      • 2020-07-25
      • 2020-01-26
      • 2021-07-03
      • 1970-01-01
      • 1970-01-01
      • 2019-12-31
      • 2019-05-19
      相关资源
      最近更新 更多