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