【问题标题】:How to Disable page bounce in Flutter Tab?如何在 Flutter Tab 中禁用页面反弹?
【发布时间】:2021-03-29 08:47:42
【问题描述】:

我有一个布局,如果tabView 的索引为0,则在AppBar 中显示一个小部件。我能做到。但是,问题是当您快速滑动tabView 时,页面会弹跳。

我们可以禁用页面反弹吗?或任何其他解决方案? 这是我的代码:

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  TabController _tabController;
  int _currentIndex;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 3, vsync: this);
    _currentIndex = 0;
    _tabController.animateTo(_currentIndex);
    _tabController.addListener(() {
      setState(() {
        _currentIndex = _tabController.index;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Page ${_currentIndex}'),
        bottom: TabBar(
          controller: _tabController,
          tabs: [
            Tab(text: 'One',),
            Tab(text: 'Two',),
            Tab(text: 'Three',),
          ],
        ),
        leading: _currentIndex == 0? Icon(Icons.ac_unit): Container(),
      ),
      body: TabBarView(
        controller: _tabController,
        children: [
          Container(color: Colors.red,),
          Container(color: Colors.green,),
          Container(color: Colors.blue,),
        ],
      ),
    );
  }

}

【问题讨论】:

    标签: flutter swipe tabview bounce


    【解决方案1】:

    TabBarView 具有默认物理 PageScrollPhysics,您可以更改它以查看最适合您的物理,AlwaysScrollablePhysics 可能会成功

    【讨论】:

    • 我试过/// /// AlwaysScrollableScrollPhysics /// BouncingScrollPhysics /// ClampingScrollPhysics /// FixedExtentScrollPhysics /// NeverScrollableScrollPhysics /// PageScrollPhysics /// RangeMaintainingScrollPhysics ///但还是不行
    猜你喜欢
    • 1970-01-01
    • 2021-10-10
    • 2014-07-16
    • 1970-01-01
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    相关资源
    最近更新 更多