简体   繁体   中英

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.

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();
                },
            )
        );
      }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM