disable swiping tabs in TabBar flutter

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),
        ],
      ),

physics: NeverScrollableScrollPhysics(),


1. You can disable swiping from TabBarView()

TabBarView(
        physics: NeverScrollableScrollPhysics(),
        controller: tabcontroler,
        children: <Widget>[]
)

2. You can disable scrooling from ListView() , PageView()

 ListView.builder(
    // you can set BouncingScrollPhysics() if you show animation when user end of list
          physics: NeverScrollableScrollPhysics(),
          itemCount: categories.length,
          itemBuilder: (BuildContext ctx, int index) {
            return CategoryItem(categories[index]);
          },
)


PageView.builder(
          physics: NeverScrollableScrollPhysics(),
)

physics accept these value :

1. BouncingScrollPhysics() : bouncing scrolling when you end/start of list
2. NeverScrollableScrollPhysics() : stop tab change OR stop list scrolling OR stop page change of pageview
3. ClampingScrollPhysics() : normal behaviour

Tags:

Flutter