我如何检测用户在没有选项卡显示的情况下向左或向右滑动,如果太像调用函数,我需要采取行动。。。我需要这个做几件事。。有可能吗?
@override
void initState() {
super.initState();
_controllerr = TabController( length: 2, vsync: this );
_controllerr!.addListener(test);
}
test(){
print('max left extent is scrolled ');
// here will outputa only when tab changed but not when swipe right or left extent where no page to show
}
bottom:TabBar(
controller: _controllerr,
tabs: const [
Tab(text: "page 1",),
Tab(text: "page 2",),
],
),
TabBarView(
controller: _controllerr,
children: [
Twxt('page1')
Twxt('page2')
]
)
尝试一下。你知道标签的编号。
TabBarView(
controller: _controllerr,
children: [
Twxt('page1')
Twxt('page2')
]
)
标签数量=屏幕数量
这样你就知道哪个是第一个标签和最后一个标签。
因此用手势检测器包裹Twxt('first_page')
、Twxt('last_page')
对于first_page:
GestureDetector(
onPanUpdate: (details) {
// for right swipe
if (details.delta.dx > 0) {
//your work
}
},
child: Twxt('first_page'),
)
对于last_page:
GestureDetector(
onPanUpdate: (details) {
// for left swipe
if (details.delta.dx < 0) {
//your work
}
},
child: Twxt('last_page'),
)
希望这将工作