在Flutter TextField中键盘可见时顶部出现的空白空间

huangapple go评论70阅读模式
英文:

Blank space on top of keyboard when keyboard is visible in Flutter TextField

问题

当键盘可见时,上方会有空白空间。我尝试了一些建议,如设置Scaffold属性resizeToAvoidBottomInset: falseextendBodyBehindAppBar: true等,但没有帮助。

我该如何处理这个问题?

英文:

When the keyboard is visible, there is a blank space above it. I tried suggestions like setting the scaffold property resizeToAvoidBottomInset: false, extendBodyBehindAppBar: true, etc but it did not help.

How can I handle this?

答案1

得分: 0

在线搜索并尝试后,我发现问题出在容纳文本字段的容器中使用了填充。

我使用了 padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 80)。这会在屏幕左右两侧添加16像素的空间,同时在屏幕顶部和底部各添加80像素的空间。因此,当键盘可见时,它会将底部的80像素空间向上推,添加到键盘上方,从而导致键盘上方的空间。

解决方案

我用 padding: const EdgeInsets.fromLTRB(16, 40, 16, 0) 替换了
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 80),这样屏幕底部就没有了空间。

英文:

After searching online and trying out things, I found out that the problem came from using padding in the container that held the textfield.

I used padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 80). This had the effect of adding 16px of space to the left and right of the screen while adding 80px of space to the top and bottom of the screen. So when the keyboard is visible, it pushes up the 80px of space from the bottom and adds it above the keyboard, hence the space above the keyboard.

Solution

I replaced
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 80) with padding: const EdgeInsets.fromLTRB(16, 40, 16, 0) so that the bottom of the screen had 0px of space.

huangapple
  • 本文由 发表于 2023年5月22日 11:14:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76302835.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定