簡體   English   中英

如何在 Flutter 中修復 Appbar 左側的項目,同時將標題保持在 Appbar 的中心?

[英]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,但我無法當場得到它。 我還需要它在不同的屏幕尺寸上工作。

圖片(我不能插入它,rep的原因)

當前代碼:

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 2flex屬性設置為 1 而不是 2,而不是用Container包裝Row小部件還包含一個名為AppBartitleSpacing ,如果設置為 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM