If you want to disable onTapped on TabBar on Flutter? 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
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; }, ) ], ), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.