4

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

jagdish
  • 440
  • 6
  • 15

2 Answers2

7

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);

jagdish
  • 440
  • 6
  • 15
2

You must have a PageController linked with your PageView, and in your PageController there is a property "initialPage".

See this good example: Creating Image Carousel in Flutter

AndDev
  • 920
  • 8
  • 10
  • hi thanks for answering. but this is not working in initState() it throws error only when it is inside initState() – jagdish Aug 10 '18 at 05:35