[英]TabBarView swipe event listener
I'm trying to setState()
whenever a TabBarView
will change its index on swipe.每当
TabBarView
在滑动时更改其索引时,我都会尝试setState()
。
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.到目前为止,我已经能够使用
_tabController.addListener()
但这只会在TabBarView
索引已经更改时触发。 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
(我相信您已经使用过)来实现。
GestureDetector(
child: yourWidget,
onPanUpdate: (d) {
if (d.delta.dx > 0) {
//triggered when swiped yourWidget in right direction
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.