[英]How to place widget to the bottom inside Form widget?
I have widget:我有小部件:
Scaffold(
appBar: ...,
body: Form(
child: ListView(
children: [
...
ElevatedButton() // Save button
]
)
)
);
So, I want to place it to the bottom of the screen.所以,我想把它放在屏幕的底部。 I tried to place it inside
Align
widget but it doesn't work.我试图将它放在
Align
小部件中,但它不起作用。 Another thing is that I have ExpansionTile
above and it can overflow the screen.另一件事是我上面有
ExpansionTile
,它可以溢出屏幕。 In this case, there mustn't be any additional space between Activate
and Save
buttons.在这种情况下,
Activate
和Save
按钮之间不能有任何额外的空间。 How to do it?怎么做?
Use MainAxisAlignment.spaceBetween.使用 MainAxisAlignment.spaceBetween。 Documentation:
文档:
Place the free space evenly between the children.
将空闲空间均匀地放在孩子之间。
bool _hasExpansionTile = false;
Scaffold(
appBar: ...,
body: Column(mainAxisAlignment: _hasExpansionTile ? MainAxisAlignment.start : MainAxisAlignment.spaceBetween, /// Checking that the expansion tile is visible
children: [
Flexible(
child: Form(
child: Column(
children: [
...
],
),
),
),
ElevatedButton(onPressed: (){}, child: Text("Send")),
],
),
);
Of course you must use setState(), when you changing the value of the _hasExpansionTile
property.当然,当您更改
_hasExpansionTile
属性的值时,您必须使用 setState()。
You can use Spacer()您可以使用 Spacer()
Scaffold( appBar: ...,
body: Form(
child: ListView(
children: [
...
Spacer(),
ElevatedButton() // Save button
]
)
) ); ));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.