Issue
I want to prevent the tab from moving even if I tap on TabBar.
TabBar(
controller: this._controller,
tabs: <Widget>[
new Tab(
text: "A",
),
new Tab(
text: "B",
),
new Tab(
text: "C",
),
])
Solution
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;
},
)
],
),
);
}
}
Answered By - Ishan Fernando
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.