flutter - 禁用 TabBar flutter 中的滑动标签

标签 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,


        ),
      ),
    );
  }
}

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

最佳答案

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

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

关于flutter - 禁用 TabBar flutter 中的滑动标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51518393/

相关文章:

flutter - 如何修复 Flutter 期望类型为 'Map<String, dynamic>' 的值,但得到类型为 'List<dynamic>' 的值

json - 如何让所有Json Body的 child 振作起来

flutter - Flutter simple_slider安装问题

dart - 无法在列中居中文本小部件

flutter - 未处理的异常 : Converting object to an encodable object failed: Instance of 'DateTime'

mysql - Dart mysql 在 map 中插入占位符

Flutter CachedNetworkImage 错误 : (CacheManager: Failed to download file) and (SocketException or HttpException)

ios - Flutter 中的 Ios 上横幅消失 (Firebase_admob)

Dart `pubspec.yaml` : Have one part of the package use Flutter without the whole package depending on Flutter

dart - Flutter Image.network 未更新