Search code examples
uiscrollviewflutter

How to scroll SingleChildScrollView programmatically?


How to scroll SingleChildScrollView programmatically?

On long Form, it is desirable to automatically scroll to a require input field.


Solution

  • There are multiple solutions :

    • Using ScrollController: Assign it to controller field of your SingleChildScrollView. And use myScrollController.animateTo or myScrollController.jumpTo
    • Use static methods of Scrollable. Possibly Scrollable.ensureVisible. But be aware that the context parameter is the context of the widget that needs to be visible. You can get that context by using GlobalKey.