禁用在 TabBar 中的滑动标签

你好,我有一个标签栏在扑动,我想禁止刷新之间的标签

      // 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,




),
),
);
}
}

我移动标签上点击每个标签栏按钮,我想禁用滑动谢谢

51214 次浏览

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

You can set the physics to NeverScrollableScrollPhysics()

TabBarView(
physics: NeverScrollableScrollPhysics(),
children: [
EditorPickTabView(),
AllProfileTabView(),
],
),

you have to use physics: NeverScrollableScrollPhysics(),

in Tabbar or ListView or PageView