有没有办法将高度设置为抽屉标题?

Jos*_*aza 13 dart flutter

我正在寻找一种方法来设置抽屉头的高度.我有这个DrawerHeader:

DrawerHeader(
        child: Text('Categories', style: TextStyle(color: Colors.white)),
        decoration: BoxDecoration(
            color: Colors.black
        ),
        margin: EdgeInsets.all(0.0),
        padding: EdgeInsets.all(0.0)
    ))
Run Code Online (Sandbox Code Playgroud)

但我没有看到将高度设置为抽屉的方法,这太大了.

Shu*_*der 30

你用Container小部件包装它.

Container(
        height: 10.0,
      child: DrawerHeader(
            child: Text('Categories', style: TextStyle(color: Colors.white)),
            decoration: BoxDecoration(
                    color: Colors.black
            ),
            margin: EdgeInsets.all(0.0),
            padding: EdgeInsets.all(0.0)
      ),
    );
Run Code Online (Sandbox Code Playgroud)

  • 太好了,它有效。您知道身高使用哪些指标吗?我将其设置为80.0以使其可见并具有AppBar高度。 (2认同)
  • 如果您查看源代码,标准高度设置为“_kDrawerHeaderHeight = 160.0 + 1.0”加上状态栏高度。(至少在当前的 v1.16.3 中) (2认同)

tvc*_*c12 7

您可以使用SizedBox小部件来调整高度DrawerHeader

new SizedBox(
   height : 120.0, 
   child  : new DrawerHeader(
      child  : new Text('Categories', style: TextStyle(color: Colors.white)),
      decoration: new BoxDecoration(color: Colors.black),
      margin : EdgeInsets.all(0.0),
      padding: EdgeInsets.all(0.0)
   ),
);
Run Code Online (Sandbox Code Playgroud)