如何在颤动中对齐平面按钮



我想知道如何在flutter中对齐按钮。我是一个新手,对于我当前的代码,我不能放入任何行、列或换行符。我想以垂直方式对齐我的按钮,但当前它水平对齐,并给我一个"RIGHT OVERFLOW BY 256 PIXELS"显示错误

return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text("You have $counts routes!"),
actions: <Widget>[
new FlatButton(
textColor: Colors.black,
padding:
EdgeInsets.fromLTRB(20, 0, 0, 10),
child: Text(
"This is route 1! n" +
rList[0] + "n"),
onPressed: () {},
),
new FlatButton(
textColor: Colors.black,
padding:
EdgeInsets.fromLTRB(20, 0, 0, 10),
child: Text(
"This is your second route! n" +
rList[1] + "n"),
onPressed: () {},
),
],
);
});

只需将按钮添加到Column

actions: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
button,
button
]
)
],

或者,如果您希望按钮与左侧对齐,请将这些按钮移动到content:

builder: (BuildContext context) {
return AlertDialog(
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("You have routes!"),
new FlatButton(
textColor: Colors.black,
child: Text(
"This is route 1! n" +
"n"),
onPressed: () {},
),
new FlatButton(
textColor: Colors.black,
child: Text(
"This is your second route! n" +
"n"),
onPressed: () {},
)
],
),
);
});

您可以使用ListView自动逐行同步。

检查下面的ListView示例。您应该将它粘贴到代码的正文段上。

//some of codes..
body: Padding(
padding: EdgeInsets.only(top: 15, left: 15, right: 15),
child: ListView(
children: <Widget>[ 
RaisedButton(
child: Text("Confirm"),
color: Colors.lightGreen,
elevation: 5.0,
onPressed: () {
save(1,context);
/*  some of codes */
},
),
RaisedButton(
child: Text("Cancel"),
color: Colors.redAccent,
elevation: 5.0,
onPressed: () {
save(0,context);
/*  some of codes */
},
),
RaisedButton(
child: Text("Pass"),
color: Colors.yellowAccent,
elevation: 5.0,
onPressed: () {
save(2,context);
/*  some of codes */
},
),
],
),
));

最新更新