3

I am creating a website with Flutter Web, and I want to navigate down in the screen with onTap on top Navbar. Like we do it in web development which will navigate to a specific id.

How can I achieve this?

Can we use ScrollController?

EDIT: I found the solution here: https://stackoverflow.com/a/58924800/11545939

Himanshu Sharma
  • 984
  • 2
  • 15
  • 40
  • 2
    Does this answer your question? [Is it possible to create links to sections in the same page in flutter web?](https://stackoverflow.com/questions/60775366/is-it-possible-to-create-links-to-sections-in-the-same-page-in-flutter-web) – void May 20 '20 at 18:47
  • 1
    Hey thanks for the source, but I am developing a responsive website so for that can I pass the controller as a variable? – Himanshu Sharma May 20 '20 at 19:20

1 Answers1

4

You should use ScrollController like this:

EDIT

var _scrollController = ScrollController();

void goUp(){
    _scrollController.animateTo(
      0.0,
      duration: Duration(milliseconds: 500),
      curve: Curves.easeInOutQuart,
    );
}

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        physics: PageScrollPhysics(),
        controller: _scrollController,
M.B
  • 609
  • 4
  • 10
  • 1
    I am creating a responsive website in which navbar is a different widget can I pass the scrollController within different files? And also my pages are not having full height, so can it cause some errors? – Himanshu Sharma May 20 '20 at 19:42
  • 1
    yes, you can pass **ScrollController** as parameter for each layout, no , it's okay – M.B May 20 '20 at 19:46