Flutter 左对齐图标按钮展开
我有一个按钮在颤振中展开的问题,我需要对齐按钮左侧的图标,我用widget行创建它,因为这是我找到的最好的方法。但是,文本没有正确居中Flutter 左对齐图标按钮展开,flutter,flutter-layout,Flutter,Flutter Layout,我有一个按钮在颤振中展开的问题,我需要对齐按钮左侧的图标,我用widget行创建它,因为这是我找到的最好的方法。但是,文本没有正确居中 SizedBox( width: double.infinity, child: RaisedButton( onPressed: () => {}, color: Colors.blue, textColor: Colors.white, child: Row( children: <
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)
)
],
)
),
),
SizedBox(
宽度:double.infinity,
孩子:升起按钮(
按下:()=>{},
颜色:颜色,蓝色,
textColor:Colors.white,
孩子:排(
儿童:[
图标(Icons.send),
扩大(
子项:Text('Enviar',textAlign:textAlign.center)
)
],
)
),
),
结果是
有没有更好的方法来制作具有这种样式的按钮(文本在所有按钮中居中,而不仅仅是在其空间中) 您可以尝试两种常见的方法,我没有实施它们,但我只是给您提供了核心想法:
- 使用,将
图标设置为
前导属性,将对齐的
文本设置为
标题属性。这种方法看起来可能更干净、更容易,但我怀疑您可能在对齐的
文本方面也有同样的问题
- 使用并用
小部件包装对齐
,设置其图标
属性以满足您的需要。然后,用对齐
的Text
小部件替换展开的Center
,这样您就不需要
属性。我想这对你来说可能更好textAlign:textAlign.Center
- 使用,将
图标设置为
前导属性,将对齐的
文本设置为
标题属性。这种方法看起来可能更干净、更容易,但我怀疑您可能在对齐的
文本方面也有同样的问题
- 使用并用
小部件包装对齐
,设置其图标
属性以满足您的需要。然后,用对齐
的Text
小部件替换展开的Center
,这样您就不需要
属性。我想这对你来说可能更好textAlign:textAlign.Center
- 问题在于行中的两个元素。这个代码应该适合你
SizedBox(
width: double.infinity,
child: RaisedButton(
onPressed: () => {},
color: Colors.blue,
textColor: Colors.white,
child: Stack(
alignment: Alignment.centerLeft,
children: <Widget>[
Icon(Icons.send),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Enviar'),
],
),
],
)
),
),
SizedBox(
宽度:double.infinity,
孩子:升起按钮(
按下:()=>{},
颜色:颜色,蓝色,
textColor:Colors.white,
子:堆栈(
对齐:alignment.centerLeft,
儿童:[
图标(Icons.send),
划船(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
文本(“Enviar”),
],
),
],
)
),
),
问题在于行中的两个元素。这个代码应该适合你
SizedBox(
width: double.infinity,
child: RaisedButton(
onPressed: () => {},
color: Colors.blue,
textColor: Colors.white,
child: Stack(
alignment: Alignment.centerLeft,
children: <Widget>[
Icon(Icons.send),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Enviar'),
],
),
],
)
),
),
SizedBox(
宽度:double.infinity,
孩子:升起按钮(
按下:()=>{},
颜色:颜色,蓝色,
textColor:Colors.white,
子:堆栈(
对齐:alignment.centerLeft,
儿童:[
图标(Icons.send),
划船(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
文本(“Enviar”),
],
),
],
)
),
),
List tile效果不太好,我将尝试使用Stack,谢谢。List tile效果不太好,我将尝试使用Stack,谢谢。