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:
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