【问题标题】:disable swiping tabs in TabBar flutter禁用 TabBar 颤动中的滑动标签
【发布时间】:2019-01-02 05:50:12
【问题描述】:

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


        ),
      ),
    );
  }
}

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

【问题讨论】:

  • 如果我理解正确,您会尝试禁用指示器,因为我不明白 TabBar 中的“滑动”是什么意思
  • 通过滑动:我的意思是你可以通过向左或向右滑动从标签移动到另一个标签
  • 看看我的回答
  • 好的,谢谢你做得好!

标签: flutter


【解决方案1】:

物理:NeverScrollableScrollPhysics(),


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

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

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

物理学接受这些值:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-04-14
      • 2017-11-07
      • 2020-10-16
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      • 2020-01-24
      • 1970-01-01
      相关资源
      最近更新 更多