简体   繁体   English

如何在按钮上方移动文本字段,该按钮在颤动中随键盘向上移动

[英]How to move textfields above a button which moves up with keyboard in flutter

I have a button aligned to the bottom of the screen so that whenever keyboard opens, the button will hold position above the keyboard.我有一个与屏幕底部对齐的按钮,这样每当键盘打开时,按钮将保持在键盘上方的位置。 This button hides textfields which is wrapped in a column inside singlechildscrollview.此按钮隐藏包含在 singlechildscrollview 中的列中的文本字段。

(TextFields move upwards with keyboard. Botton stacked above the column is causing the issue) (TextFields 随键盘向上移动。在列上方堆叠的 Botton 是导致问题的原因)

Image before opening keyboard打开键盘前的图像

Image after opening keyboard打开键盘后的图像

I tried wrap column in a Padding widget and gave a bottom padding but still the same result.我尝试在 Padding 小部件中包装列并给出底部填充,但结果仍然相同。 Please suggest a way to position textfields above the button.请建议一种将文本字段放置在按钮上方的方法。

Note: First time poster.注:第一次海报。 Please forgive if there is any mistakes.如有错误请见谅。 Thank You谢谢你

return SafeArea(
  child: Stack(
    fit: StackFit.expand,
    children: [
      SingleChildScrollView(
        child: Container(
          child: Column(
            children: [
              Container(
                color: Colors.deepOrange,
                width: double.maxFinite,
                height: height * 0.3,
              ),
              Container(
                color: Colors.black,
                width: double.maxFinite,
                height: height * 0.56,
                child: SingleChildScrollView(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Utils().colSpacer20,
                      TextBox(hint: "name", editingController: _controller),
                      Utils().colSpacer20,
                      TextBox(hint: "name", editingController: _controller),
                      Utils().colSpacer20,
                      TextBox(hint: "name", editingController: _controller),
                      Utils().colSpacer20,
                      TextBox(hint: "name", editingController: _controller),
                      Utils().colSpacer20,
                      TextBox(hint: "name", editingController: _controller)
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
      Positioned(
        bottom: 0,
        left: 0,
        right: 0,
        child: FlatButton(
          color: Colors.blue[900],
          onPressed: () {},
          child: Text(
            "Save",
            style: TextStyles().subTextStyleWhite,
          ),
          minWidth: double.maxFinite,
          height: height * 0.1,
        ),
      )
    ],
  ),
);

Edit: scrollPadding property of TextField widget solved the issue.编辑:TextField 小部件的 scrollPadding 属性解决了这个问题。 Thanks @Anitesh Reddy.谢谢@Anitesh Reddy。

Keep padding/margin or sizedBox( height:height*0.12 ) at the bottom of the column so that the widget in positioned will move down and leave space.将 padding/margin 或 sizedBox( height:height*0.12 ) 保留在列的底部,以便定位的小部件将向下移动并留出空间。

use scrollpadding property使用滚动填充属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM