如何在 flutter 中让 Appbar 的 IconButton 居中

How to center the IconButton of Appbar in flutter

我在使用 flutter 应用程序时发现应用程序栏中有问题。 图标按钮不在应用栏中央

这是我的代码。

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

IconButton 不在应用栏或导航栏的中心。

您可以通过以下解决方法来实现此目的,因为操作通常在标题之后,如文档所述 AppBar class

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。