Use case
Description:
Currently, DefaultTabController doesn’t provide a direct way to listen to tab changes.
If we want to know the current tab index, we have to use a TabController manually and add a listener, which removes the simplicity of using DefaultTabController.
It would be very useful if DefaultTabController exposed an onChanged callback that returns the current tab index whenever the user changes tabs.
Expected behavior:
When the user switches tabs (by tapping or swiping), the onChanged callback should be triggered with the updated index.
Proposal
DefaultTabController(
length: 3,
onChanged: (index) {
print('Current tab index: $index');
},
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(text: 'Tab 1'),
Tab(text: 'Tab 2'),
Tab(text: 'Tab 3'),
],
),
),
body: TabBarView(
children: [
Center(child: Text('Tab 1')),
Center(child: Text('Tab 2')),
Center(child: Text('Tab 3')),
],
),
),
);
Use case
Description:
Currently,
DefaultTabControllerdoesn’t provide a direct way to listen to tab changes.If we want to know the current tab index, we have to use a
TabControllermanually and add a listener, which removes the simplicity of usingDefaultTabController.It would be very useful if
DefaultTabControllerexposed anonChangedcallback that returns the current tab index whenever the user changes tabs.Expected behavior:
When the user switches tabs (by tapping or swiping), the
onChangedcallback should be triggered with the updated index.Proposal