Home > Enterprise >  Howto take the index value of tabs when the user swap?
Howto take the index value of tabs when the user swap?

Time:10-19

I need when the user click on tabs or drag them, i take the value of index.

enter image description here

This Code works only when the use click, But on Swap between them no action added! How could i take the index value when the user swap?

The code is:

 TabBar(
        onTap: (int index) {
          context.read<ScheduledPossibleDayCubit>().tabClicked(index: index);
        },
        tabs: []})

CodePudding user response:

You should use the custom tabController and attach the listener to it.

Like this:

_tabController = new TabController(length: 2, vsync: this, initialIndex: 0);
_tabController.addListener(() {
  print(_tabController.index);
});
  • Related