flutter - 禁用 TabBar 颤动中的滑动标签
问题描述
您好,我在 Flutter 中有一个标签栏,我想禁用标签之间的滑动
// 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,
),
),
);
}
}
我在点击每个标签栏按钮时移动标签,我想禁用滑动谢谢
解决方案
physics
您可以通过使用该属性更改页面视图应如何响应用户输入来实现这一点。我们有一个NeverScrollableScrollPhysics
为此目的,所以只需更改physics
为这样的:
TabBarView(
physics: NeverScrollableScrollPhysics(),
controller: tabcontroler,
children: <Widget>[
Container(color: Colors.red),
Container(color: Colors.green),
Container(color: Colors.blue),
],
),