如何防止键盘将内容向上推?

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

How to prevent the keyboard from pushing content upwards?

问题

有一个包含列的脚手架。列中有两个小部件;一个是图像,另一个是文本。图像包裹在一个扩展小部件中,因此将文本推到屏幕底部。如果以这种设计打开键盘,键盘会将文本向上推,而不是遮挡它。

是否有可能使键盘遮挡小部件而不是将它们向上推,而不需要任何外部包?

英文:

There is a scaffold with a column. Inside the column there are two widgets; one is an image and the other is a text. The image is wrapped around an expanded widget therefore, pushing the text to the bottom of the screen. If you open the keyboard with such a design then, the keyboard will push the text upwards instead of walking over it.

Is it possible to make the keyboard walk over widgets instead of pushing them upwards without any external packages?

答案1

得分: 4

尝试在您的Scaffold小部件下添加resizeToAvoidBottomInset:false。之后键盘将不会推动列向上。

英文:

Try resizeToAvoidBottomInset:false under your Scaffold widget. After that keyboard won't push column up.

答案2

得分: 1

你可以使用SingleChildScrollView小部件和NeverScrollableScrollPhysics(),如下例所示,防止键盘打开时屏幕调整大小:

    return Scaffold(
             body: SingleChildScrollView(
               physics: NeverScrollableScrollPhysics(),
                child: ...
英文:

You can use SingleChildScrollView widget and NeverScrollableScrollPhysics() like below example to prevent screen resizing when keyboard is open

return Scaffold(
         body: SingleChildScrollView(
           physics: NeverScrollableScrollPhysics(),
            child: ...

huangapple
  • 本文由 发表于 2023年3月31日 21:46:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75899277.html
匿名

发表评论

匿名网友

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

确定