简体   繁体   English

TabBarView 滑动事件监听器

[英]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.

相关问题 颤动 TabBarView 有时不会在手势滑动时触发 - flutter TabBarView sometimes not triggering on gesture swipe 如何在 flutter 中实现 TabBarView 滑动刷新? - How to implement TabBarView with swipe to refresh in flutter? 当我滑动时,我的应用程序正在调用所有 TabBarView 内容 - My app is calling all TabBarView contents when I swipe 如何在 Flutter 中的 TabBarView 中从最后一个选项卡滑动到第一个选项卡 - How to swipe from last to first tab in TabBarView in Flutter 标签栏指示器颜色在 flutter 中的 tabbarview 滑动时没有更新? - Tab bar indicator color is not updating on swipe of tabbarview in flutter? Tabbarview和Pageview无法在页面之间滑动 - Tabbarview and Pageview without being able to swipe between pages 是否可以从TabBarView内容区域滑动到相邻的PageView页面? - Is it possible to swipe from an TabBarView content area to an adjacent PageView page? 更改 Flutter 中的 TabbarView 当从另一个 class 按下按钮时,还需要使可滑动 - Change TabbarView in Flutter When pressed button from another class and also need to make swipe-able 如何使用 TabBarView 滚动到下一个选项卡进入 TabBarView - How to scroll to next tab using TabBarView into TabBarView TabBarView动态更新列表 - TabBarView dynamic update List
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM