如何在 PreferredSizeWidget 中垂直居中小部件

Ale*_*ink 6 dart flutter

我想在bottom:我的AppBar.

我已经尝试过的一些事情是:
1. 将文本包裹在Center(...)小部件中
2. 将文本包裹在 a 中Column(...)并使用crossAxisAlignment: CrossAxisAlignment.center

bottom:Sektion是PreferredSizeWidget,不提供任何格式化的Widget。

appBar: new AppBar(
      actions: <Widget>[
        IconButton(
          icon: Icon(Icons.settings),
          onPressed: () {
            print("Settings Icon");
          },
        ),
      ],
      bottom: PreferredSize(
        preferredSize: Size(130.0, 130.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            new Text(
              'N/A',      
           ),
          ],
        ),
      ),
    ),
Run Code Online (Sandbox Code Playgroud)

我在这里发现了这个问题:https : //github.com/flutter/flutter/issues/16262文本居中但重现代码对我不起作用。

文本应该是像红线一样的地方(见图)

应用栏

谢谢!

Vin*_*nto 4

PreferredSizeWidget不会对其子级施加大小限制,因此您必须将其Column包装在具有定义高度的小部件中才能添加对齐。

另外,mainAxisAlignment应该使用,因为这是Column.

  bottom: PreferredSize(
    preferredSize: Size(130.0, 130.0),
    child: Container(
      height: 130,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          new Text(
            'N/A',      
        ),
        ],
      ),
    ),
  )
Run Code Online (Sandbox Code Playgroud)