I think you have to add listner to tab click and then change the index to 0 again. In this we need to add controller and we can set index through that.
class TabBarDemoWidget extends State<TabBarDemo> with TickerProviderStateMixin{
@override
Widget build(BuildContext context) {
int _tabIndex = 0;
var tab = TabController(
initialIndex: 0,
length: 3,
vsync: this
);
void _handleTabSelection(){
setState(() {
tab.index = _tabIndex;
});
}
tab.addListener(_handleTabSelection);
return DefaultTabController(
length: 3,
initialIndex: 0,
child: TabBar(
labelColor: Colors.teal,
controller: tab,
tabs: [
GestureDetector(
child:Tab(
icon:
Icon(
Icons.directions_car)) ,
onTap: (){
_tabIndex = 0;
},
),GestureDetector(
child:Tab(
icon: Icon(Icons.directions_car)) ,
onTap: (){
_tabIndex = 0;
},
),GestureDetector(
child:Tab(
icon: Icon(Icons.directions_car)) ,
onTap: (){
_tabIndex = 0;
},
)
],
),
);
}
}