将图标对准左按钮展开

问题描述 投票:0回答:1

我的按钮在颤动中扩展时遇到问题,我需要将图标对准按钮的左侧,我使用小部件Row来实现,因为这是我找到的最佳方法。但是,文本没有正确居中。

   SizedBox(
    width: double.infinity,
    child: RaisedButton(
    onPressed: () => {},
    color: Colors.blue,
    textColor: Colors.white,
    child: Row(
     children: <Widget>[
      Icon(Icons.send),
      Expanded(
       child: Text('Enviar', textAlign: TextAlign.center)
      )
     ],
    )
   ),
  ),

结果是

enter image description here

是否有更好的方法来制作具有这种样式的按钮(文本在所有按钮中居中,不仅在其空间内?)?

flutter flutter-layout
1个回答
0
投票

您可以尝试两种常用方法,我没有实现它们,但我只是给您提供核心思想:

  • 使用ListTile并将Icon设置为leading属性,并将对齐的Text设置为title属性。这种方法看起来更干净,更容易,但是我怀疑您可能在对齐Text方面遇到相同的问题。
  • 使用Stack,并用Icon小部件包装Align,并设置其alignment属性以满足您的需要。然后,将Expanded替换为CenterText小部件,您将不需要textAlign: TextAlign.center属性。我认为这可能更适合您。
© www.soinside.com 2019 - 2024. All rights reserved.