当键盘出现时,Flutter 小部件会调整大小.如何防止这种情况? [英] When the keyboard appears, the Flutter widgets resize. How to prevent this?

查看:26
本文介绍了当键盘出现时,Flutter 小部件会调整大小.如何防止这种情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列像这样展开的小部件:

I have a Column of Expanded widgets like this:

 return new Container(
      child: new Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          new Expanded(
            flex: 1,
            child: convertFrom,
          ),
          new Expanded(
            flex: 1,
            child: convertTo,
          ),
          new Expanded(
            flex: 1,
            child: description,
          ),
        ],
      ),
    );

看起来像这样:

convertFrom,包括一个 TextField.当我点击此文本字段时,Android 键盘会出现在屏幕上.这会改变屏幕大小,因此小部件会像这样调整大小:

convertFrom, includes a TextField. When I tap on this text field, the Android keyboard appears on the screen. This changes the screen size, so the widgets resize like this:

有没有办法让键盘覆盖"屏幕,这样我的列就不会调整大小?如果我不使用 Expanded 小部件并为每个小部件硬编码高度,则小部件不会调整大小,但是当键盘出现时我会收到黑白条纹错误(因为没有t 足够的空间).这也不适用于所有屏幕尺寸.

Is there a way to have the keyboard "overlay" the screen so that my Column doesn't resize? If I don't use Expanded widgets and hardcode a height for each widget, the widgets don't resize, but I get the black-and-yellow striped error when the keyboard appears (because there isn't enough space). This also isn't flexible for all screen sizes.

我不确定这是 Android 特定的还是 Flutter 特定的.

I'm not sure if this is an Android-specific or Flutter-specific.

推荐答案

更新答案

resizeToAvoidBottomPadding 现在不推荐使用.

更新的解决方案是将 resizeToAvoidBottomInset 属性设置为 false.

The updated solution is to set resizeToAvoidBottomInset property to false.

原答案

在您的 Scaffold 中,将 resizeToAvoidBottomPadding 属性设置为 false.

In your Scaffold, set resizeToAvoidBottomPadding property to false.

这篇关于当键盘出现时,Flutter 小部件会调整大小.如何防止这种情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆