【问题标题】:Scroll TextFormField above keyboard in ListView在 ListView 中的键盘上方滚动 TextFormField
【发布时间】:2018-06-12 13:31:20
【问题描述】:

我的应用中有以下抽屉:

当我按下密码TextFormField 时,我得到以下信息:

如您所见,密码TextFormField 已被覆盖。按照here的建议,我试图解决这个问题:

class _LoginDrawer extends State<LoginDrawer> {
  static var _listViewScrollController = new ScrollController();

  @override
  Widget build(BuildContext context) => new Drawer(
    child: new ListView(
      controller: _listViewScrollController,
      children: <Widget>[
        // ...
        new Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          child: new GestureDetector(
            onTap: () {
              SchedulerBinding.instance.addPostFrameCallback((_) {
                _listViewScrollController.jumpTo(
                 _listViewScrollController.position.maxScrollExtent);
              });
            },
            child: new TextFormField(
                obscureText: true,
                decoration: new InputDecoration(labelText: "Password")),
          ),
        ),
      ],
    ),
  );
}

但这并不能解决问题,该应用程序的行为与以前相同。还有一些人建议使用反转的ListView,然后使用listViewController.jumpTo(0.0),但这会导致不良效果,即所有小部件都从底部开始:

【问题讨论】:

  • 这是颤振的问题,检查这是否与您的情况有关stackoverflow.com/questions/46841637/…
  • 这个问题应该被修复(至少在master
  • 你有解决办法吗?
  • Na bruh,这就像一百万年前,我什至不再开发这个应用程序了,skrrr。

标签: flutter


【解决方案1】:

用 Scaffold 包裹您的列表视图并设置 resizeToAvoidBottomInset: true,此属性。也许这可以帮助你。

【讨论】:

    【解决方案2】:

    根据@aziza 发布的问题,它转到了这个 github 问题:

    https://github.com/flutter/flutter/issues/7032

    解决方案是使用一个小部件将元素向上移动到键盘之外。这是flutter中的一个bug。

    【讨论】:

      【解决方案3】:

      由于您的TextFields 很少,并且您使用过ListView,因此您可以将ListView 反转,最后添加.reversed.toList(),如下所示:

      new ListView(
        reverse: true, //this line reverse the list
        controller: _listViewScrollController,
        children: <Widget>[
          // ...
          new Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16.0),
            child: new GestureDetector(
              onTap: () {
                SchedulerBinding.instance.addPostFrameCallback((_) {
                  _listViewScrollController.jumpTo(
                    _listViewScrollController.position.maxScrollExtent);
                });
              },
              child: new TextFormField(
                  obscureText: true,
                  decoration: new InputDecoration(labelText: "Password")),
            ),
          ),
        ].reversed.toList(), // reverse it backword(Iterable) and convert it to ListView
      ),
      

      根据@collinJackson,如果您有更多文本字段,这将失败。

      在此处阅读更多信息:https://github.com/flutter/flutter/issues/10826

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-30
        • 2017-10-22
        • 2019-09-29
        • 2017-08-11
        相关资源
        最近更新 更多