【问题标题】:How to handle TabBar with ListView in Flutter?Flutter 中如何用 ListView 处理 TabBar?
【发布时间】:2019-09-05 04:37:24
【问题描述】:

我花了几个小时才找到如何在滚动 listView 直到 (x) 项目/标题时更改选项卡的色调,

我开始向here学习flutter

UI 看起来像:

我想知道如何处理 ListViewtabBar 以防万一我滚动到 Flutter 很棒 51 tabBar 指示器应该变为正确,同样的事情应该工作使用 tabBar,当我按下 tabBar index 51 时,ListView 应该滚动到 Flutter is awesome 51

谁能指导我如何做到这一点?

【问题讨论】:

    标签: listview dart flutter tabbar


    【解决方案1】:

    你需要使用

    TabController

    _tabController.animateTo((index))
    

    结合

    ScrollController

    final _position = ... // half or top depending on tab selection itemsize and count 
    _scrollController.animateTo(_position,
            curve: Curves.linear, duration: Duration(milliseconds: 500));
    

    如果您的列表项具有相同的高度,您可以依赖滚动的偏移量和位置来检测它何时达到一半。

    Here is an implementation of the ScrollController that will aid you.

    【讨论】:

    • 您能告诉我为什么TabControllerScrollController 会破坏滚动时隐藏的标题吗?
    • 我不知道这个问题。也许最好创建一个新的问题线程并提供完整的详细信息。
    猜你喜欢
    • 2020-08-18
    • 2019-07-12
    • 2021-01-26
    • 2021-10-19
    • 2020-06-14
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多