[英]How to fix item on left side of Appbar, while keep title in center of Appbar in Flutter?
我想把“Logo2”小部件放在左邊,而“Title logo”放在中間。 我正在嘗試使用 Expanded inside Row 和 Stack,但我無法當場得到它。 我還需要它在不同的屏幕尺寸上工作。
當前代碼:
appBar: AppBar(
leading: Icon(Icons.menu),
centerTitle: true,
title: Container(child: Row(
children: <Widget>[
Expanded(flex:2, child: Text("Logo 2")),
Expanded(flex:4, child: Text("Title logo")),
],
)),
actions: <Widget>[
IconButton(
icon: Icon(Icons.person_pin),
onPressed: (){},
)
],
),
您可以直接傳遞Row
小部件並將Logo 2
的flex
屬性設置為 1 而不是 2,而不是用Container
包裝Row
小部件還包含一個名為AppBar
的titleSpacing
,如果設置為 0,則有助於保持標題centered
。 下面的工作代碼:
appBar: AppBar(
titleSpacing: 0,
leading: Icon(Icons.menu),
centerTitle: true,
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
flex: 1,
child: Text('Logo 2'),
),
Expanded(
flex: 2,
child: Text('Title Logo')
)
],
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.person_pin),
onPressed: (){},
)
],
),
希望這能回答你的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.