禁用在TabBar颤动中滑动选项卡

And*_*oud 26 flutter

您好我在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,


        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

我正在移动选项卡点击每个标签栏按钮,我想禁用刷卡谢谢

Rao*_*che 55

您可以通过更改页面视图应使用physics属性响应用户输入的方式来实现这一点.我们有一个NeverScrollableScrollPhysics为此目的,所以只需改变physics这样:

TabBarView(
        physics: NeverScrollableScrollPhysics(),
        controller: tabcontroler,
        children: <Widget>[
          Container(color: Colors.red),
          Container(color: Colors.green),
          Container(color: Colors.blue),
        ],
      ),
Run Code Online (Sandbox Code Playgroud)


San*_*inh 10

物理:NeverScrollableScrollPhysics(),


1.您可以禁用从TabBarView()滑动

TabBarView(
        physics: NeverScrollableScrollPhysics(),
        controller: tabcontroler,
        children: <Widget>[]
)
Run Code Online (Sandbox Code Playgroud)

2.您可以从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(),
)
Run Code Online (Sandbox Code Playgroud)

物理接受这些值:

1. BouncingScrollPhysics():在列表结束/开始时弹跳滚动
2. NeverScrollableScrollPhysics():停止选项卡更改或停止列表滚动或页面浏览的页面更改
3. ClampingScrollPhysics() :正常行为