Is there a way to add listeners in DefaultTabController?
- Define a tabController and a listener (once changing tab, it will be triggered twice)
class _ScreenState extends State<Screen> with SingleTickerProviderStateMixin { late TabController tabController; @override void initState() { super.initState(); this.tabController = TabController(length: 3, vsync: this); this.tabController.addListener(() { if (this.tabController.indexIsChanging) { print(this.tabController.index); print(this.tabController.previousIndex); } }); }}
- Pass it to the TabBar and TabBarView, like:
TabBar( controller: this.tabController, tabs: [ Tab(text: "0"), Tab(text: "1"), Tab(text: "2"), ],)TabBarView(controller: this.tabController, children: [...])