如何在Flutter中将AppBar中的IconButton居中显示

4

我正在开发一个Flutter应用程序,发现了一个AppBar的问题。图标按钮不在AppBar的中心。

以下是我的代码。

appBar: AppBar(
    automaticallyImplyLeading: false,
    actions: <Widget>[
      IconButton(
          icon: Icon(Icons.home),
          onPressed: null,
      )
    ],
  ),

IconButton未位于应用栏或导航栏的中心。

1个回答

4

由于文档中指出操作通常在标题之后,因此您可以执行以下解决方法AppBar类,以实现此目的。

appBar: AppBar(
            automaticallyImplyLeading: false,
            centerTitle: true,
            title: Row(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                IconButton(
                  icon: Icon(Icons.home),
                  onPressed: null,
                ),
                IconButton(
                  icon: Icon(Icons.trending_up),
                  onPressed: null,
                ),
                IconButton(
                  icon: Icon(Icons.people_outline),
                  onPressed: null,
                ),
                IconButton(
                  icon: Icon(Icons.person_outline),
                  onPressed: null,
                ),
                IconButton(
                  icon: Icon(Icons.notifications_none),
                  onPressed: null,
                ),
                IconButton(icon: Icon(Icons.search), onPressed: null),
                IconButton(
                  icon: Icon(Icons.brightness_5),
                  onPressed: null,
                ),
              ],
            )),

也许在您的情况下,考虑使用TabBar可能更合适。

3
不需要使用 centerTitle: true - Vettiyanakan
3
不,你需要将其设置为true,这样才能在Android和IOS中都使其居中。在Android中,默认情况下左对齐,在iOS中默认居中。 - Crazy Lazy Cat

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接