Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable swiping tabs in TabBar flutter

Tags:

flutter

Hello I have a tab bar in Flutter and I want to disable swiping between tabs

      // Set the bottom navigation bar       bottomNavigationBar: new Material(          // set the color of the bottom navigation bar         color: const Color(0xFFF7F7F7),         // set the tab bar as the child of bottom navigation bar         child: new TabBar(           tabs: <Tab>[             new Tab(               // set icon to the tab               icon: new Icon(Icons.home,color: Colors.black),             ),             new Tab(               icon: new Icon(Icons.favorite,color: Colors.black),             ),             new Tab(               icon: new Icon(Icons.search,color: Colors.black),             ),             new Tab(               icon: new Icon(Icons.settings,color: Colors.black),             ),           ],           // setup the controller           controller: controller,           ),       ),     );   } } 

I am moving tabs on clicking each tab bar button and I want to disable swiping thank you

like image 673
André Abboud Avatar asked Jul 25 '18 12:07

André Abboud


People also ask

How do I turn off tabs in Flutter?

Question answered by Sunisha S (source). Use IgnorePointer. It will disable the click action of tabs.

What is DefaultTabController in Flutter?

DefaultTabController is an inherited widget that is used to share a TabController with a TabBar or a TabBarView. It's used when sharing an explicitly created TabController isn't convenient because the tab bar widgets are created by a stateless parent widget or by different parent widgets.

Can we use TabBar without AppBar in Flutter?

TabBar with labels without AppBar Instead, we can use PreferredSize widget. Since TabBar has preferredSize , we should use it to decide the height. Yes!


1 Answers

you can achieve that by changing how the page view should respond to user input using the physics property. and we have a NeverScrollableScrollPhysics for that purpose so just change physics to that like this :

TabBarView(         physics: NeverScrollableScrollPhysics(),         controller: tabcontroler,         children: <Widget>[           Container(color: Colors.red),           Container(color: Colors.green),           Container(color: Colors.blue),         ],       ), 
like image 57
Raouf Rahiche Avatar answered Sep 30 '22 00:09

Raouf Rahiche