Scroll TextFormField above keyboard in ListView

7,296

Solution 1

Wrap your listview with Scaffold and set resizeToAvoidBottomInset: true, this property. May be this can help you.

Solution 2

According to the issue @aziza posted, it goes to this github issue:

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

And the solution is to use a widget that moves the elements up out of the way of the keyboard. This is a bug in flutter.

Share:
7,296
janosch
Author by

janosch

Updated on December 03, 2022

Comments

  • janosch
    janosch 25 days

    I have the following drawer in my app:

    When I press on the password TextFormField I get the following:

    enter image description here

    As you can see, the password TextFormField is covered. I tried to solve this, as suggested 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")),
              ),
            ),
          ],
        ),
      );
    }
    

    But this doesn't solve it, the app just behaves the same as before. Also some people suggested to use a ListView that is reversed and then use listViewController.jumpTo(0.0) but this led to the unwanted effect, that all widgets started from the bottom:

    enter image description here