Home > Enterprise >  Flutter: How do I detect tab onclick when the current tab is selected?
Flutter: How do I detect tab onclick when the current tab is selected?

Time:11-10

While I can detect tab changes with:

controller.addListener((){
   print('my index is'  controller.index.toString());
});

How do I detect if the same tab is tapped? I'd like to have an action when user clicks on the home tab to go to the top of the scroll page while user is at home.

CodePudding user response:

You can use onItemSelected option in your TabView widget.

CodePudding user response:

You can implement to use onTap method in TabBar class.

TabBar(
   onTap: (index) {
      print(controller.index);
      print(index);
      if (controller.index == index) {
         print('Same Tab Clicked');
      }
   },
   tabs: [
      ...
   ]

});
  • Related