Limbou / expandable_page_view

MIT License
88 stars 36 forks source link

[Request] A way to set the index on load #44

Closed petteremil closed 2 years ago

petteremil commented 2 years ago

Hello! I was wondering if there is a way to set the starting index for the ExpandablePageView.builder; I couldn't see a way, but thought I'd check with you whether I was missing something?

Limbou commented 2 years ago

Hi @petteremil, thanks for the question. As with standard PageView, you can set an initial index by creating a PageController and passing it to ExpandablePageView. Here is a small code example:

class _ExampleWidgetState extends State<ExampleWidget> {
  late PageController _pageController;

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

  @override
  Widget build(BuildContext context) {
    return ExpandablePageView.builder(
      itemCount: 5,
      itemBuilder: (_, __) => const SizedBox(),
      controller: _pageController,
    );
  }
}

I hope it helps. If you have any more question, please let me know. I'm going to close this ticket for now.