可以通过将AppBar中的title属性设置为空,然后使用Row和Expanded小部件来实现水平居中对齐。在Row widget中添加返回按钮和必要的间距。以下是一个示例代码:
AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {},
),
title: Text(''),
centerTitle: true,
actions: [
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
),
],
bottom: TabBar(
tabs: [
Tab(text: 'Tab 1'),
Tab(text: 'Tab 2'),
],
),
),
在这个例子中,我们使用了一个空文本作为AppBar的标题。这样可以确保返回按钮和search按钮在AppBar中间对齐。同时,在行部件中使用了Expanded小部件来填充AppBar和back按钮之间的空隙,使它们居中显示。