Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jumping to another page in PageView() not working

Tags:

flutter

dart

I have following pageview()

Widget _build() {
    return PageView(
        children:<Widget>[
            page1,
            page2,
            page3
        ]
    )
}

now when this _build method is called i want to show page2 and not initial page.

I have tried this code

initState(){
    pageController = PageController();
    pageController.jumpToPage(2);
}

but here 2nd line throws this error

ScrollController not attached to any scroll views

how can i show a particular page using PageView() ?
Thanks

like image 874
jagdish Avatar asked Jan 28 '23 15:01

jagdish


1 Answers

Here's what i did
to show a particular page we have to pass its index to PageController constructor
like this
pageController = PageController(initialPage: widget.activePageIndex);

like image 154
jagdish Avatar answered Jan 30 '23 04:01

jagdish