简体   繁体   English

如何检测 TabBarView 刚刚被拖动?

[英]How can I detect that a TabBarView has just been dragged?

The TabBar widget has an onTap() callback that allows to detect when the user has just pressed a tab. TabBar 小部件有一个 onTap() 回调,它允许检测用户何时刚刚按下了一个选项卡。 This is useful so that we we can prepare the new tabView to show some dynamic data.这很有用,因此我们可以准备新的 tabView 来显示一些动态数据。

The TabBar widget has also a drag functionality that allows to change the tabView displayed ( similar result as tapping on another tab). TabBar 小部件还有一个拖动功能,允许更改显示的 tabView(类似于点击另一个选项卡的结果)。 But in this case there seems to be no way to prepare the new TabView because there's no an onDrag() callback.但在这种情况下,似乎没有办法准备新的 TabView,因为没有 onDrag() 回调。

So the question is : is there a way to detect that a TabBarView has just been dragged?所以问题是:有没有办法检测到 TabBarView 刚刚被拖动?

The TabBar widget has an onTap() callback that allows to detect when the user has just pressed a tab. TabBar 小部件有一个 onTap() 回调,它允许检测用户何时刚刚按下了一个选项卡。 This is useful so that we we can prepare the new tabView to show some dynamic data.这很有用,因此我们可以准备新的 tabView 来显示一些动态数据。

The TabBar widget has also a drag functionality that allows to change the tabView displayed ( similar result as tapping on another tab). TabBar 小部件还有一个拖动功能,允许更改显示的 tabView(类似于点击另一个选项卡的结果)。 But in this case there seems to be no way to prepare the new TabView because there's no an onDrag() callback.但是在这种情况下,由于没有onDrag()回调,因此似乎无法准备新的TabView。

So the question is : is there a way to detect that a TabBarView has just been dragged?所以问题是:有没有办法检测到 TabBarView 刚刚被拖动?

The TabBar widget has an onTap() callback that allows to detect when the user has just pressed a tab. TabBar 小部件有一个 onTap() 回调,它允许检测用户何时刚刚按下了一个选项卡。 This is useful so that we we can prepare the new tabView to show some dynamic data.这很有用,因此我们可以准备新的 tabView 来显示一些动态数据。

The TabBar widget has also a drag functionality that allows to change the tabView displayed ( similar result as tapping on another tab). TabBar 小部件还有一个拖动功能,允许更改显示的 tabView(类似于点击另一个选项卡的结果)。 But in this case there seems to be no way to prepare the new TabView because there's no an onDrag() callback.但是在这种情况下,由于没有onDrag()回调,因此似乎无法准备新的TabView。

So the question is : is there a way to detect that a TabBarView has just been dragged?所以问题是:有没有办法检测到 TabBarView 刚刚被拖动?

The TabBar widget has an onTap() callback that allows to detect when the user has just pressed a tab. TabBar 小部件有一个 onTap() 回调,它允许检测用户何时刚刚按下了一个选项卡。 This is useful so that we we can prepare the new tabView to show some dynamic data.这很有用,因此我们可以准备新的 tabView 来显示一些动态数据。

The TabBar widget has also a drag functionality that allows to change the tabView displayed ( similar result as tapping on another tab). TabBar 小部件还有一个拖动功能,允许更改显示的 tabView(类似于点击另一个选项卡的结果)。 But in this case there seems to be no way to prepare the new TabView because there's no an onDrag() callback.但是在这种情况下,由于没有onDrag()回调,因此似乎无法准备新的TabView。

So the question is : is there a way to detect that a TabBarView has just been dragged?所以问题是:有没有办法检测到 TabBarView 刚刚被拖动?

The TabBar widget has an onTap() callback that allows to detect when the user has just pressed a tab. TabBar 小部件有一个 onTap() 回调,它允许检测用户何时刚刚按下了一个选项卡。 This is useful so that we we can prepare the new tabView to show some dynamic data.这很有用,因此我们可以准备新的 tabView 来显示一些动态数据。

The TabBar widget has also a drag functionality that allows to change the tabView displayed ( similar result as tapping on another tab). TabBar 小部件还有一个拖动功能,允许更改显示的 tabView(类似于点击另一个选项卡的结果)。 But in this case there seems to be no way to prepare the new TabView because there's no an onDrag() callback.但是在这种情况下,由于没有onDrag()回调,因此似乎无法准备新的TabView。

So the question is : is there a way to detect that a TabBarView has just been dragged?所以问题是:有没有办法检测到 TabBarView 刚刚被拖动?

The TabBar widget has an onTap() callback that allows to detect when the user has just pressed a tab. TabBar 小部件有一个 onTap() 回调,它允许检测用户何时刚刚按下了一个选项卡。 This is useful so that we we can prepare the new tabView to show some dynamic data.这很有用,因此我们可以准备新的 tabView 来显示一些动态数据。

The TabBar widget has also a drag functionality that allows to change the tabView displayed ( similar result as tapping on another tab). TabBar 小部件还有一个拖动功能,允许更改显示的 tabView(类似于点击另一个选项卡的结果)。 But in this case there seems to be no way to prepare the new TabView because there's no an onDrag() callback.但是在这种情况下,由于没有onDrag()回调,因此似乎无法准备新的TabView。

So the question is : is there a way to detect that a TabBarView has just been dragged?所以问题是:有没有办法检测到 TabBarView 刚刚被拖动?

This works for me:这对我有用:

int _tab = 0;

@override
void initState() {
 super.initState();

 _tabController = TabController(
  length: _tabs.length, 
  vsync: this
 );

 _tabController.animation!.addListener(_tabListener);
}

void _tabListener(){
 if(_tab != _tabController.animation!.value.round()){
  setState(() {
   _tab = _tabController.animation!.value.round();
  });
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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