简体   繁体   中英

TabBarView swipe event listener

I'm trying to setState() whenever a TabBarView will change its index on swipe.

TabBarView(
  controller: _tabController,
  children: [
    fooScreen(),
    barScreen(),
  ]

So far I've been able to use _tabController.addListener() but this only triggers whenever the TabBarView index has already changed. Is there any way to get it to trigger when the index is going to change?

Since you need your event to get triggered on swipe then you could wrap the widget you are interested in listening for the swipe gesture .

In code this could be achieved using the GestureDetector (which I'm sure you've used already).

GestureDetector(
 child: yourWidget,

 onPanUpdate: (d) {
  if (d.delta.dx > 0) {
    //triggered when swiped yourWidget in right direction
  }
});

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