【问题标题】:How to disable tabBarView from swiping如何禁用 tabBarView 滑动
【发布时间】:2019-09-29 12:35:49
【问题描述】:

我有 TabBar 和 TabBarView 根据我从服务器获取的数据,我想在这些选项卡上禁用。

_tabController = TabController(vsync: this, length: 3, initialIndex: 0)
      ..addListener(() {
        print(_tabController.index);
        if (_album != null &&
            (_album['description'] == null ||
                _album['description'].toString().isEmpty) &&
            _tabController.index == 2) {
          setState(() {
            _tabController.index = 1;
            //it must be last tabController.index but I don't know how to impelement
          });
        }
      });

如果我们点击一​​个标签,它不会移动,一切都是正确的

但是如果我们滑动到第三页,它会有一个奇怪的行为,因为标签栏视图没有被禁用

那么我们如何解决刷卡问题呢?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    你可以添加物理:NeverScrollableScrollPhysics() 像下面的例子

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

    完整参考https://inducesmile.com/google-flutter/how-to-disable-swiping-tabs-in-flutter-tabbar/

    【讨论】:

      猜你喜欢
      • 2021-08-16
      • 1970-01-01
      • 2019-07-25
      • 2015-03-30
      • 1970-01-01
      • 2014-04-01
      • 2018-04-30
      • 1970-01-01
      相关资源
      最近更新 更多