首页 > 解决方案 > 如何使 Appbar 的 IconButton 在颤动中居中

问题描述

我使用颤振应用程序并在应用栏中看到问题。图标按钮不在应用栏的中心。

这是我的代码。

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

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

标签: flutterandroid-appbarlayoutappbarflutter-appbar

解决方案


这是您可以采取的一种解决方法来实现这一点,因为操作通常在标题之后,因为文档说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 。


推荐阅读