【问题标题】:How to fix item on left side of Appbar, while keep title in center of Appbar in Flutter?如何修复 Appbar 左侧的项目,同时在 Flutter 中将标题保持在 Appbar 的中心?
【发布时间】:2019-11-14 19:36:46
【问题描述】:

我想把“Logo2”小部件放在左边,而“Title logo”放在中间。我尝试在行内使用扩展,并使用堆栈,但我无法当场得到它。我还需要它在不同的屏幕尺寸上工作。

当前代码:

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: (){},
    )
  ],
),

【问题讨论】:

  • 我认为如果centerTile 为假,该行将起作用。
  • 不会改变任何东西。

标签: flutter dart


【解决方案1】:

您可以直接传递Row小部件并将Logo 2flex属性设置为1而不是2。AppBar小部件还包含一个名为@987654329的属性,而不是用Container包装Row @ 如果设置为 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: (){},
            )
          ],
        ),

希望这能回答你的问题。

【讨论】:

  • 我试过了,但是“Title logo”没有居中,我相信是因为action Widget改变了center title属性。
猜你喜欢
  • 2020-03-13
  • 2021-06-18
  • 1970-01-01
  • 2022-12-16
  • 1970-01-01
  • 1970-01-01
  • 2021-02-10
  • 2020-04-02
  • 1970-01-01
相关资源
最近更新 更多