How can I scroll to specific section in flutter ?
I have webpage with
header
main
footer
When i click footer
, I want to go to the footer
section.
I just know we have to use ScrollController
but ran out of resources to figure out solution, seems easy but couldn’t find a solution.
Headsup, It is not just simple ListView
, so ListView's
approach to go to specific index wouldn’t work.
2
Answers
Global Key
onPressed
using_containerKey.currentContext
:You can use
Scrollable.ensureVisible(contextToBeVisible)
Just pass the context of the e.g. footer and the scrolling will happen if e.g. combined with an onTap event:
Official docs: https://api.flutter.dev/flutter/widgets/Scrollable/ensureVisible.html
And there are numerous examples here on SO.