我想要一个简单的输入框,下面有按钮,我想把它放在屏幕的中央。
这是我的代码:
Widget build(BuildContext context) {
return new Container(
decoration: new BoxDecoration(color: Colors.white10),
child: new Center(
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(border: OutlineInputBorder())),
IconButton(
icon: Icon(Icons.volume_up),
tooltip: 'Increase volume by 10%',
onPressed: () { setState(() { _volume *= 1.1; }); },)
],
)
),
);
}
但是它会出现在屏幕的顶部,即使我使用了
Center()
小部件。 最佳答案
您只需要垂直居中,使用mainAxisAlignment
和crossAxisAlignment
Widget build(BuildContext context) {
return new Container(
decoration: new BoxDecoration(color: Colors.white10),
child: new Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextField(
decoration: InputDecoration(border: OutlineInputBorder())),
IconButton(
icon: Icon(Icons.volume_up),
tooltip: 'Increase volume by 10%',
onPressed: () { setState(() { _volume *= 1.1; }); },)
],
)
),
);
}
关于flutter - 将输入字段和按钮放在屏幕中央,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54817390/