繁体   English   中英

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

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

我有一个与屏幕底部对齐的按钮,这样每当键盘打开时,按钮将保持在键盘上方的位置。 此按钮隐藏包含在 singlechildscrollview 中的列中的文本字段。

(TextFields 随键盘向上移动。在列上方堆叠的 Botton 是导致问题的原因)

打开键盘前的图像

打开键盘后的图像

我尝试在 Padding 小部件中包装列并给出底部填充,但结果仍然相同。 请建议一种将文本字段放置在按钮上方的方法。

注:第一次海报。 如有错误请见谅。 谢谢你

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,
        ),
      )
    ],
  ),
);

编辑:TextField 小部件的 scrollPadding 属性解决了这个问题。 谢谢@Anitesh Reddy。

将 padding/margin 或 sizedBox( height:height*0.12 ) 保留在列的底部,以便定位的小部件将向下移动并留出空间。

使用滚动填充属性

暂无
暂无

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

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