Search code examples
fluttertabbarpageviews

How to swipe from last to first tab in TabBarView in Flutter


Can someone tell me if it's there is a way to make a TabBarView or PageView to swipe to initialIndex/initialPage or last one if the current view is the initial one?

I couldn't find a method to do it.


Solution

  • I managed to solve it with PageView and setting the initial page to a bigger number and not setting itemCount.

        int _curentPage = 0;
        final initialPage = 98;
    
        @override
          void initState() {
            pageController = PageController(initialPage: initialPage);
            super.initState();
          }
    
    @override
      void dispose() {
        pageController.dispose();
        super.dispose();
      }
    
         @override
          Widget build(BuildContext context) {
            return Scaffold(
              body: PageView.builder(
                    controller: pageController,
                    itemBuilder: (context, index) {
                      return eventPages[(eventPages.length - (initialPage - index - 1) % eventPages.length - 1)];
                    },
                    onPageChanged: (pageNum) {
                      _curentPage = (eventPages.length - (initialPage - pageNum - 1) % eventPages.length - 1);
                      _updateBottomBar();
                    },
                )
            );
          }