【发布时间】:2019-11-19 14:28:56
【问题描述】:
我有一个登录页面,其中包含三个字段和一个位于页面中心的按钮。在同一页面的底部,我需要垂直显示三个按钮。我如何在 Flutter 中做到这一点?任何建议都会非常有帮助。在此先感谢。
【问题讨论】:
-
请贴出你试过的代码。
标签: flutter dart flutter-layout
我有一个登录页面,其中包含三个字段和一个位于页面中心的按钮。在同一页面的底部,我需要垂直显示三个按钮。我如何在 Flutter 中做到这一点?任何建议都会非常有帮助。在此先感谢。
【问题讨论】:
标签: flutter dart flutter-layout
你的问题不清楚,我认为你需要在一个列的底部放置3个按钮。
return Scaffold(
appBar: AppBar(),
body: Container(
padding:
EdgeInsets.only(left: 20.0, right: 20.0, top: 25.0, bottom: 25.0),
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(hintText: 'Text Field 1'),
),
TextField(
decoration: InputDecoration(hintText: 'Text Field 2'),
),
TextField(
decoration: InputDecoration(hintText: 'Text Field 3'),
),
SizedBox(
height: 25.0,
),
MaterialButton(
onPressed: () {},
child: Text('Button'),
color: Colors.blue,
minWidth: double.infinity,
),
Expanded(
child: SizedBox(),
),
MaterialButton(
onPressed: () {},
child: Text('Button 1'),
color: Colors.blue,
minWidth: double.infinity,
),
MaterialButton(
onPressed: () {},
child: Text('Button 2'),
color: Colors.blue,
minWidth: double.infinity,
),
MaterialButton(
onPressed: () {},
child: Text('Button 3'),
color: Colors.blue,
minWidth: double.infinity,
),
],
),
),
);
Expanded 将填补空白
如果你的问题不同,请给我更多细节
【讨论】:
你必须使用Stack和Positioned来实现你想要的,查看下面的例子
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(
padding:
EdgeInsets.only(left: 20.0, right: 20.0, top: 25.0, bottom: 25.0),
child: Stack(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
decoration: InputDecoration(hintText: 'Text Field 1'),
),
TextField(
decoration: InputDecoration(hintText: 'Text Field 2'),
),
TextField(
decoration: InputDecoration(hintText: 'Text Field 3'),
),
SizedBox(
height: 25.0,
),
MaterialButton(
onPressed: () {},
child: Text('Button'),
color: Colors.blue,
minWidth: double.infinity,
),
],
),
Positioned(
bottom: 0.0,
left: 0.0,
right: 0.0,
child: Column(
children: <Widget>[
MaterialButton(
onPressed: () {},
child: Text('Button 1'),
color: Colors.blue,
minWidth: double.infinity,
),
MaterialButton(
onPressed: () {},
child: Text('Button 2'),
color: Colors.blue,
minWidth: double.infinity,
),
MaterialButton(
onPressed: () {},
child: Text('Button 3'),
color: Colors.blue,
minWidth: double.infinity,
),
],
),
),
],
),
),
);
}
【讨论】: