flutter tabbar切换监听及索引获取

参考:https://www.jianshu.com/p/f1347e658fa6

 

定义

late TabController _controller;

 

在 void initState()中监听

 

  tabController = TabController(length: tabs.length, vsync: this)
      ..addListener(() {
         // or (tabController.indexIsChanging) 
        if (!tabController.indexIsChanging) {  // 
          print("监听切换tab ${tabController.index} "); // 打印索引
        }
      });

 

posted @ 2022-12-10 16:19  lude1994  阅读(1100)  评论(0编辑  收藏  举报