Button 如何在颤振中对齐按钮中的文本?
我只想做最简单的事情:我只想有一个文本向右对齐的按钮。不知什么原因,我搞不懂 我试过textAlign:textAlign.right,但它仍然在中间。我试着用mainAxisAlignment.end在按钮内部划一行,但没有,仍然在中间。出于某种原因,如果我在列而不是行上使用主轴对齐.end(将其放在底部而不是右侧),它会起作用 这就是我到目前为止所做的:Button 如何在颤振中对齐按钮中的文本?,button,text,dart,flutter,alignment,Button,Text,Dart,Flutter,Alignment,我只想做最简单的事情:我只想有一个文本向右对齐的按钮。不知什么原因,我搞不懂 我试过textAlign:textAlign.right,但它仍然在中间。我试着用mainAxisAlignment.end在按钮内部划一行,但没有,仍然在中间。出于某种原因,如果我在列而不是行上使用主轴对齐.end(将其放在底部而不是右侧),它会起作用 这就是我到目前为止所做的: FlatButton( color: Colors.black, child: Row( mainAxisAlig
FlatButton(
color: Colors.black,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Text(
"M",
textAlign: TextAlign.right,
style: TextStyle(
color: mColor, fontSize: 10.0),
),
],
),
FlatButton(
颜色:颜色,黑色,
孩子:排(
mainAxisAlignment:mainAxisAlignment.end,
儿童:[
正文(
“M”,
textAlign:textAlign.right,
样式:TextStyle(
颜色:mColor,字体大小:10.0),
),
],
),
将其放入墨水池中
InkWell(
onTap: doSomething,
child: SizedBox(
height: 100,
width: 100,
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black)),
child: Text(
'hello',
textAlign: TextAlign.right,
),
),
),
),
你应该把你的“文本”放在“对齐”中,使你的文本左对齐、右对齐、上对齐、下对齐等等-
FlatButton(
color: Colors.blue,
textColor: Colors.white,
padding: EdgeInsets.all(8.0),
splashColor: Colors.blueAccent,
onPressed: () {
/*...*/
},
child: Align(
alignment: Alignment.center,
child: Text(
"Flat",
style: TextStyle(fontSize: 20.0),
textAlign: TextAlign.center
),
))
我发现在FlatButton小部件中使用填充值非常有效 见下面的例子
FlatButton(
onPressed: () {
/*...*/
},
padding: EdgeInsets.only(right: 10.0, bottom: 1.0, top: 1.0),
child: Text(
'Getting Started',
style: TextStyle(
color: Colors.blueGrey[900],
fontSize: 12.0
), //TextStyle
), //Text
), //FlatButton
它对我有用
ButtonTheme(
child: FlatButton(
padding: EdgeInsets.all(0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Button text",
style: TextStyle(
color: ThemeColors.primaryDark,
fontWeight: FontWeight.normal,
fontSize: ThemeSizes.normalFont,
),
textAlign: TextAlign.left,
),
),
onPressed: () => _doSomething(),
),
)
我知道这很古老,但我现在正在做的是,以防它对任何人都有帮助
TextButton(
onPressed: () {},
style: Theme.of(context)
.textButtonTheme
.style!
.copyWith(alignment: Alignment.centerLeft),
因为它与此处的样式相匹配,所以它不起作用。
FlatButton(颜色:Colors.black,child:Align(对齐:alignment.centerRight,child:Text(“M”,样式:TextStyle(颜色:mColor,fontSize:10.0),),
该代码生成但更改为对齐。Topcenter生成感谢!这应该是公认的答案!这很有效,谢谢!此外,我发现您可以使用堆栈将按钮覆盖在文本小部件的顶部,但这更整洁。嗯,这是个糟糕的主意:)抱歉。如果文本更改,并且按钮具有固定宽度或全屏宽度,您将遇到大问题,您甚至不知道:)只有在按钮没有任何类型的设置宽度时,使用填充才会起作用