温馨提示:本文翻译自stackoverflow.com,查看原文请点击:dart - Flutter

dart - Flutter

发布于 2020-03-28 23:33:48

我需要在Flutter应用中更改应用栏的高度。我使用以下代码:

 Widget build(BuildContext context) {
 return Scaffold(
    appBar: PreferredSize(
      preferredSize: Size.fromHeight(100.0),
      child: AppBar(
        automaticallyImplyLeading: false, 
        flexibleSpace: Container(),
        centerTitle: true,
        title: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Icon(Icons.search),
            Icon(Icons.home),
            PopupMenuButton<String>(
              icon: Icon(Icons.menu),
                itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
                  PopupMenuItem<String>(
                    value: "1",
                    child: Text('Hello'),
                  ),
                  PopupMenuItem<String>(
                    value: "2",
                    child: Text('World'),
                  ),
                ]
            )
          ],
        ),
      ),
    ),
    body: Container());
}

这是我的结果:

在此处输入图片说明

高度已更改,但我需要将内容垂直居中对齐。我尝试使用此选项,但不起作用:

        automaticallyImplyLeading: false, 
        flexibleSpace: Container(),
        centerTitle: true,

有什么建议吗?

查看更多

查看更多

提问者
FetFrumos
被浏览
61
pedrotech 2020-01-31 22:19

https://dartpad.dartlang.org/115b02f36456fe9579cb8daf092bd906

class MyAppBar extends StatelessWidget with PreferredSizeWidget {
  final double appBarHeight = 120.0;
  @override
  get preferredSize => Size.fromHeight(appBarHeight);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          AppBar(
            automaticallyImplyLeading: false, 
            elevation: 0,
            title: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Icon(Icons.search),
                Icon(Icons.home),
                PopupMenuButton<String>(
                  icon: Icon(Icons.menu),
                  itemBuilder: (BuildContext context) =>
                      <PopupMenuEntry<String>>[
                    PopupMenuItem<String>(
                      value: "1",
                      child: Text('Hello'),
                    ),
                    PopupMenuItem<String>(
                      value: "2",
                      child: Text('World'),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
      decoration: BoxDecoration(
        boxShadow: <BoxShadow>[
          BoxShadow(
              color: Colors.black54,
              blurRadius: 15.0,
              offset: Offset(0.0, 0.75))
        ],
        color:
            ThemeData.dark().appBarTheme.color ?? ThemeData.dark().primaryColor,
      ),
    );
  }
}

在此处输入图片说明

发布
问题

分享
好友

手机
浏览

扫码手机浏览