How to implement navigation in a single page web application in flutter?

2.5k views Asked by At

I am creating a bit complex in terms of UI single page web application in flutter. As a last piece I am struggling with implementing navigation, all examples foundable online are focused on multi-page usecases.

AppBar(
 Row(
   children: [
     Button("Gallery"),
     Button("Faq"),
    Button("Contact"), #after clicking this button
   ]
  ),
),
SingleChildScrollView(
  child: Column( 
    children: [
      GallerySection(...),
      FaqSection(...), 
      ContactSection(...), #scroll to this section/container
    ]
  ),
);

The idea is to implement navigation that after pressing one the appBar buttons user is being scrolled to requested section. I do not care that much for the url formatting it can stay www.flutter-single-page.com/#but having back navigation would be outstanding :-), but optional.

Do you know a way how this can be accomplished?

1

There are 1 answers

2
RegularGuy On BEST ANSWER

You could use a scrollController to scroll to a widget with it's ensureVisible method. Then you just assign a key to each section and call ensureVisible for navigation.

Check this answer as an example