如何检测Flutter中的TabBar变化? [英] How to detect TabBar change in Flutter?
本文介绍了如何检测Flutter中的TabBar变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我滑动然后在控制台上打印某些内容时,我需要检测TabBar,我该怎么做?这是我的代码。
I need to detect TabBar when I swipe then print somethings on console, how I can do that? This is my code.
bottomNavigationBar: new Material(
color: Colors.blueAccent,
child: new TabBar(
onTap: (int index){ setState(() {
_onTap(index);
});},
indicatorColor: Colors.white,
controller: controller,
tabs: <Widget>[
new Tab(icon: new Icon(Icons.shopping_basket)),
new Tab(icon: new Icon(Icons.store)),
new Tab(icon: new Icon(Icons.local_offer)),
new Tab(icon: new Icon(Icons.assignment)),
new Tab(icon: new Icon(Icons.settings)),
],
)
),
推荐答案
您需要在选项卡控制器中添加侦听器-可能在 initState
中。
You need to add a listener to your tab controller - maybe in initState
.
controller.addListener((){
print('my index is'+ controller.index.toString());
});
这篇关于如何检测Flutter中的TabBar变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文