How to disable scrolling back to top on a SingleCh

2019-08-16 17:00发布

I have a SingleChildScrollView widget whose child is a Form widget in Flutter. Whenever I made some changes to the radio buttons or switches inside the form and calling setState() method, the view scrolls to the top. How can I avoid this behavior?

1条回答
SAY GOODBYE
2楼-- · 2019-08-16 17:56

I would recommend passing through a custom ScrollController when constructing your SingleChildScrollView widget.

ScrollController has a property called 'keepScrollOffset' which you need to set to true.

From the documentation at https://docs.flutter.io/flutter/widgets/ScrollController-class.html

keepScrollOffset → bool Each time a scroll completes, save the current scroll offset with PageStorage and restore it if this controller's scrollable is recreated. [...] final

查看更多
登录 后发表回答