Closed MennaCC closed 6 months ago
Hi @MennaCC , I'm sorry for the delay on this.
You can already achieve this behavior by adding a listener to the TabController
:
TabController tabController = TabController(
length: 2,
);
tabController.addListener(onTabChanged);
Where onTabChanged
is something like:
onTabChanged() {
if (tabController.indexIsChanging) return;
switch (tabController.index) {
case 0:
// do something
break;
case 1:
// do something
break;
}
}
Hi @MennaCC , I'm sorry for the delay on this. You can already achieve this behavior by adding a listener to the
TabController
:TabController tabController = TabController( length: 2, ); tabController.addListener(onTabChanged);
Where
onTabChanged
is something like:onTabChanged() { if (tabController.indexIsChanging) return; switch (tabController.index) { case 0: // do something break; case 1: // do something break; } }
I think that the expected default behavior for the already implemented onTap function is to change the view whether it is tapped or swiped since the swipe detection is already implemented (thank you for that btw) . Instead of tampering with the already implemented onTap I just made the onSwipe and used it instead of the onTap.
I think it is always better to encapsulate all the controller and addListener stuff inside the package itself for its user (like what's done in the onTap), and much simpler to use especially if the views change dynamically due to the object I associate with the tab.
Thank you for the explanation @MennaCC . That's a fair point, however, after inspecting Flutter's default TabBar implementation:
https://api.flutter.dev/flutter/material/TabBar/onTap.html
I noticed that only the onTap method is provided. Which I assume it is because it is difficult to distinguish between onTap and onSwipe gestures from the TabBar itself.
Therefore, I'll keep this package as it is. I'm sorry and I hope you understand.
can you at least add the modification to the onTap?
On Thu, 11 Apr 2024, 9:22 am Afonso Raposo, @.***> wrote:
Thank you for the explanation @MennaCC https://github.com/MennaCC . That's a fair point, however, after inspecting Flutter's default TabBar implementation:
https://api.flutter.dev/flutter/material/TabBar/onTap.html
I noticed that only the onTap method is provided. Which I assume it is because it is difficult to distinguish between onTap and onSwipe gestures from the TabBar itself.
Therefore, I'll keep this package as it is. I'm sorry and I hope you understand.
— Reply to this email directly, view it on GitHub https://github.com/afonsocraposo/buttons_tabbar/issues/46#issuecomment-2049073736, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWS6PXEUMOG5OTUO7KAQXTY4Y2Z3AVCNFSM6AAAAABFHVDXDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBZGA3TGNZTGY . You are receiving this because you were mentioned.Message ID: @.***>
Hey @MennaCC!
In Flutter's documentation, it says that the onTap
method for TabBar
is:
An optional callback that's called when the TabBar is tapped. The callback is applied to the index of the tab where the tap occurred.
I believe the implementation in ButtonsTabBar
the onTap
callback does the same, no?
Can you elaborate what behavior you are expecting from the onTap
callback?
I'm expecting that the behavior I set for the onTap happens on "index change" by either tap or swipe.
Hi @MennaCC! I think it's better to keep the onTap
behavior similar to what Flutter provides on the native TabBar
:
https://api.flutter.dev/flutter/material/TabBar/onTap.html
i also need onSwipe callback ;(
Hey @dipu0! Please find the answer to your problem here: https://stackoverflow.com/questions/55485466/how-to-detect-tabbar-change-in-flutter
Feature Request
Description
Need to set "onSwipe" callback in TabBarView paramaters like setting "onTap" to buttonsBar, so I can call an async function to update the view dynamically