gpt4 book ai didi

flutter - Flutter-如何更改AppBar的高度并对齐标题垂直中心?

转载 作者:行者123 更新时间:2023-12-03 03:08:47 31 4
gpt4 key购买 nike

我需要在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());
}

这是我的结果:

enter image description here

高度已更改,但我需要将内容垂直居中对齐。
我尝试使用此选项,但不起作用:
        automaticallyImplyLeading: false, 
flexibleSpace: Container(),
centerTitle: true,

有什么建议吗?

最佳答案

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,
),
);
}
}

enter image description here

关于flutter - Flutter-如何更改AppBar的高度并对齐标题垂直中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60001360/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com