简体   繁体   English

如何将小部件放置在表单小部件的底部?

[英]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.在这种情况下, ActivateSave按钮之间不能有任何额外的空间。 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.

相关问题 如何在 Flutter 页面底部放置文本小部件? - How to Place Text Widget at the Bottom of Flutter Page? Flutter:如何将小部件放置在容器内固定居中小部件下方 - Flutter : How to place a Widget below fixed Centered Widget inside a Container 如何将 Text/ListTile 小部件(在抽屉内)放置在手机屏幕的最底部 - How to place a Text/ListTile widget (inside Drawer) at the very bottom of the phone screen 如何在表单小部件内导航? - How to navigate inside a form widget? 如何在 custompaint 小部件中放置内容? - How to place content inside custompaint widget? 使用列表视图时如何将小部件放置到页面底部? - How to place a widget to bottom of page while using listview? 如何在 flutter 中将一个小部件放置在屏幕顶部,将另一个放置在底部? - How to place one widget at top of the screen and other at the bottom in flutter? setState() 在我的小部件中不起作用,因为我的小部件构建在小部件树的底部,那么我如何重建该小部件? - setState() is not working inside my widget, since my that widget is built on the bottom of the widget tree, then how can I rebuild that widget? 颤振将小部件放在屏幕底部展开 - flutter place widget on bottom of screen in expanded Flutter:如何在底部导航栏中添加列小部件 - Flutter: How to add a column widget inside a bottom navigation bar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM