Search code examples
androidflutterbuttondartpageviews

Flutter: How to navigate in PageView with a RaisedButton or move pageViewController with button


I want to create a section of Page View in which we can navigate between its children Pages on pressing a unique raised button.

Each button will navigate to different page.

How can I achieve this?


Solution

  • You have to have this controller:

    
      @override
      void initState() {
        super.initState();
        _pageController = PageController();
      }
    

    After this you can define your PageView widget. Now the raised button can have this for controlling the

                            onPressed: () {
                              if (_pageController.hasClients) {
                                _pageController.animateToPage(
                                  1,
                                  duration: const Duration(milliseconds: 400),
                                  curve: Curves.easeInOut,
                                );
                              }
                            }, 
    

    You have to note the index of the page.