How to go back to initial page in in a PageView thats in a TabBarView when the TabBarView changes?

223 views
Skip to first unread message

Scott J

unread,
Mar 16, 2021, 11:52:56 AM3/16/21
to Flutter Development (flutter-dev)
I have a TabBarView with a PageView that has 2 pages in it. I have access to the indexIsChanging property in the TabBar. How can I go back to page 1 whenever the TabBar changes?

Scott J

unread,
Mar 17, 2021, 11:09:14 AM3/17/21
to Flutter Development (flutter-dev)
Bump, is there a way to listen to indexIsChanging? I tried to do something like this in initState:

_controller = PageController(
      initialPage: 0,
    )..addListener(() {
        if (widget.tabController.indexIsChanging) 
        //goto previousPage....
      });

Other than widget.tabController.indexIsChanging not updating ....When the if statement is true
the statement doesn't execute once, it goes off multiple times. Not sure if I'm using it right

Suzuki Tomohiro

unread,
Mar 17, 2021, 11:45:11 AM3/17/21
to Flutter Development (flutter-dev)
Can you share the URL of PageController documentation?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/75618457-a769-476a-8eb7-cd4562b99e79n%40googlegroups.com.

Scott J

unread,
Mar 17, 2021, 11:47:22 AM3/17/21
to Flutter Development (flutter-dev)

Suzuki Tomohiro

unread,
Mar 17, 2021, 12:14:41 PM3/17/21
to Scott J, Flutter Development (flutter-dev)

Scott J

unread,
Mar 17, 2021, 1:17:47 PM3/17/21
to Flutter Development (flutter-dev)
I think I'm asking the wrong questions, let me see if I can explain it better.
problem2.gif

In the gif, I'm in the groups tab, if I click the button I go to the second page in that tab. What I would like to happen is when I switch tabs, the page controller goes back to the first page. With tabController there's a property called indexIsChanging and it's only true when tab changes. What I want to know is how can I go back to the first page when the tab is changed.

Suzuki Tomohiro

unread,
Mar 17, 2021, 8:32:38 PM3/17/21
to Scott J, Flutter Development (flutter-dev)
IndexIsChanging seems irrelevant.

I think that you just need to call animateToPage when a tab button is tapped.

Reply all
Reply to author
Forward
0 new messages