Flutter 如何从抽屉阅读器上卸下衬垫

Flutter 如何从抽屉阅读器上卸下衬垫,flutter,flutter-layout,Flutter,Flutter Layout,这是我的抽屉阅读器: class MyDrawerHeader extends StatefulWidget { @override _MyDrawerHeaderState createState() => _MyDrawerHeaderState(); } class _MyDrawerHeaderState extends State<MyDrawerHeader> { @override Widget build(BuildContext contex

这是我的
抽屉阅读器

class MyDrawerHeader extends StatefulWidget {
  @override
  _MyDrawerHeaderState createState() => _MyDrawerHeaderState();
}

class _MyDrawerHeaderState extends State<MyDrawerHeader> {
  @override
  Widget build(BuildContext context) {
    return DrawerHeader(
      padding: EdgeInsets.all(0),
      margin: EdgeInsets.all(0),
      child: Center(child: Text('Header', style: Theme.of(context).textTheme.headline))
    );
  }
}
类MyDrawerHeader扩展StatefulWidget{
@凌驾
_MyDroperHeaderState createState()=>\u MyDroperHeaderState();
}
类_MyDrawerHeaderState扩展状态{
@凌驾
小部件构建(构建上下文){
回程抽屉式卸料器(
填充:边缘集。全部(0),
边距:所有边集(0),
child:Center(child:Text('Header',style:Theme.of(context.textTheme.headline))
);
}
}
如您所见,我将
抽屉阅读器中的
填充
边距
设置为
0
,但我的标题是这样显示的:

它太大了,我不能把它缩小。我不知道为什么会这样呈现,我查看了
DrawerHeader
源代码,没有看到任何内容覆盖了我的
填充
边距

为了确定问题出在
抽屉阅读器
中,当我将其替换为
容器
时会发生这种情况:

它的工作,因为它应该


我是遗漏了什么,还是这是颤振中的错误?

尝试用下面的代码替换你的抽屉

drawer: Drawer(
    child: DrawerHeader(
      child: ListView(
        children: <Widget>[
          Container(
            alignment: Alignment.topLeft,
            child: Text('Header', style: Theme.of(context).textTheme.headline),
          ),
        ],
      ),
    ),
  ), 
抽屉:抽屉(
儿童:抽屉阅读器(
子:ListView(
儿童:[
容器(
对齐:alignment.topLeft,
子项:Text('Header',style:Theme.of(context).textTheme.headline),
),
],
),
),
), 

抽屉阅读器上总是有填充物。如果你查阅资料来源:

@override
Widget build(BuildContext context) {
  assert(debugCheckHasMaterial(context));
  assert(debugCheckHasMediaQuery(context));
  final ThemeData theme = Theme.of(context);
  final double statusBarHeight = MediaQuery.of(context).padding.top;
  return Container(
    height: statusBarHeight + _kDrawerHeaderHeight,
    margin: margin,
    decoration: BoxDecoration(
      border: Border(
        bottom: Divider.createBorderSide(context),
      ),
    ),
    child: AnimatedContainer(
      padding: padding.add(EdgeInsets.only(top: statusBarHeight)),
      decoration: decoration,
      duration: duration,
      curve: curve,
      child: child == null ? null : DefaultTextStyle(
        style: theme.textTheme.body2,
        child: MediaQuery.removePadding(
          context: context,
          removeTop: true,
          child: child,
        ),
      ),
    ),
  );
}
您可以自定义此代码:

高度:statusBarHeight+kDrawerHeaderHeight
-这里是收割台的总高度


padding:padding.add(EdgeInsets.only(top:statusBarHeight))
-这里是
DrawerHeader中子元素的padding

哦,是的,你说得对<代码>\u kDrawerHeaderHeight
定义在类的顶部,我错过了!谢谢您好,欢迎来到stackoverflow,谢谢您的回答。你能不能简单地解释一下你解决了什么问题以及你是如何解决的,而不是仅仅发布一段代码?这将帮助将来发现这个问题的人更好地理解这个问题以及如何处理它。padding:EdgeInsets.all(0.0),适合我。感谢@NaeemIbrahim之前的评论应该是可以接受的答案。最简单的解决方案,可直接满足op的要求。
drawer: Drawer(
          child: ListView(
            padding: EdgeInsets.zero,
            children: [
              DrawerHeader(
                padding: EdgeInsets.all(0.0),
                child: Container(
                  color: Theme.of(context).primaryColor,
                ),
              ),
              ListTile(
                title: Text("Home"),
              )
            ],
          ),
        ),