【问题标题】:How to center the IconButton of Appbar in flutter如何使 Appbar 的 IconButton 在颤动中居中
【发布时间】:2020-04-16 16:29:19
【问题描述】:

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

这是我的代码。

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

图标按钮不在应用栏或导航栏的中心。

【问题讨论】:

    标签: flutter android-appbarlayout appbar flutter-appbar


    【解决方案1】:

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

    【讨论】:

    • 你不需要centerTitle: true,
    • @AbyMathew 不,您必须将其设置为 true,这样您才能在 Android 和 IOS 中获得中心位置。在 Android 中默认为左对齐,在 IOS 中为居中。
    猜你喜欢
    • 2021-10-04
    • 2021-07-31
    • 2020-12-19
    • 2021-12-02
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多