如何检测颤动的滑动tabbar?

问题描述 投票:0回答:1

当我滑动然后在控制台上打印某些内容时,我需要检测tabbar,我该怎么做?这是我的代码

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)),

               ],
             )
           ),
dart flutter tabbar
1个回答
0
投票

您需要向选项卡控制器添加一个监听器 - 可能在initState中。

controller.addListener((){
   print('my index is'+ controller.index.toString());
});
© www.soinside.com 2019 - 2024. All rights reserved.