luckybug38
luckybug38

Reputation: 31

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

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.

Upvotes: 2

Views: 3630

Answers (2)

KuKu
KuKu

Reputation: 7492

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: [
      ...
   ]

});

Upvotes: 5

M Karimi
M Karimi

Reputation: 3485

You can use onItemSelected option in your TabView widget.

Upvotes: 0

Related Questions