79219568

Date: 2024-11-24 07:34:57
Score: 0.5
Natty:
Report link

I've followed @CoastalB and its worked but the problem is it's take some delay to get index. so I've used two separate listener (animate and tap) for get index.

The current code is implemented with GetX, but you can easily apply this approach with stateful widget:

class GenerateController extends GetxController with GetSingleTickerProviderStateMixin {
  late TabController tabController;
  RxInt activeTabIndex = 0.obs;

  @override
  void onInit() {
    super.onInit();
    tabController = TabController(vsync: this, length: 2);
    tabController.addListener(_onTabIndexChanged);
    tabController.animation?.addListener(_onTabAnimation);
  }

  void _onTabIndexChanged() {
    // Fires at the end of tab change animation
    activeTabIndex.value = tabController.animation!.value.round();
    print("Tab index finalized: ${tabController.index}");
  }

  void _onTabAnimation() {
    // Fires during the animation
    activeTabIndex.value = tabController.animation!.value.round();
  }
  @override
  void onClose() {
    tabController.dispose();
    super.onClose();
  }
}
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @CoastalB
  • Low reputation (1):
Posted by: Rifat Khan