在AppBar按钮中对齐文本

时间:2020-06-15 14:55:54

标签: flutter dart

我正在尝试将文本对齐到位于AppBar的action属性中的按钮中。

enter image description here

我希望文本在右侧。

     AppBar(
        title: Text('Profile'),
        actions: <Widget>[
          FlatButton(
            color: Colors.red,
            padding: EdgeInsets.zero,
            child: Align(
              alignment: Alignment.centerRight,
              child: Text(
                'Done',
                textAlign: TextAlign.right,
              ),
            ),
            onPressed: () {},
          )
        ],
      )

我什至尝试了MaterialRawButton,但结果相同……无论您做什么,文本都将位于按钮的中心

2 个答案:

答案 0 :(得分:1)

尝试在Align中使用widthFactor,它可以让我们在特定位置移动。 只需在Align中添加此代码

widthFactor: 2.5

答案 1 :(得分:1)

您也可以改用IconButton并将其添加到图标参数文本小部件中。

             IconButton(
              icon: Text(
                'Done',
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
              ),
              padding: EdgeInsets.zero)