搜尋套件、儲存庫與 APP 分類

套件詳情v0.4.1

super_sliver_list

SliverList 和 ListView 的即插即用取代品,可處理具有變動範圍的大清單,並支援跳轉/動畫至特定項目。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
13萬
喜歡數
301
Pub 分數
150

安裝套件

flutter pub add super_sliver_list

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

SuperSliverList 是 SliverList 和 ListView 的高性能即插即用替代品,專為高效管理具有可變項目高度的大列表而設計。它支援平滑滾動、跳轉至項目導航,以及項目之間的動畫過渡。基於 Flutter 的自訂捲動檢視系統建構,透過僅建立可見組件來優化渲染,非常適合動態或複雜的清單結構。此套件在需要跨多個平台實現響應式、可擴展清單互動的應用中特別實用。

適用情境

  • 大型動態列表,項目大小可變
  • 平滑跳轉到特定列表項目
  • 動畫列表過渡
  • 複雜的可捲動介面
  • 高性能列表渲染
  • 跨平台列表組件

主要特色

  • 變數範圍支援
  • 跳躍並動畫顯示項目
  • 大型數據集的優化渲染
  • SliverList/ListView 的即插即用替代品
  • 內建的滾動位置持久化
  • 跨平台相容性

適合對象

  • 開發複雜可捲動 UI 的開發者
  • 包含大量或動態資料集的應用程式
  • 效能關鍵的列表實作
  • 跨平台 Flutter 應用程式
  • 需要進階清單導航的使用者

使用建議

  • 需要理解基於 Sliver 的佈局
  • 對於非常小的清單,可能有開銷
  • 與原始的 Sliver 小部件相比,自訂選項有限
  • 最適合頻繁更新的可捲動內容
  • 不建議用於靜態、簡單的清單

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

SliverList and ListView - Supercharged

See the live example of SuperSliverList.

SuperSliverList and SuperListView are drop in replacement widgets for SliverList and ListView with greatly improved performance and additional features:

Fast scrolling with large amount of items with variable extents

SliverList performance degrades heavily when quickly scrolling through a large amount of items with different extents, requiring workarounds such as using FixedExtentSliverList or prototype items. SuperSliverList uses different layout algorithm and can handle virtually unlimited number of items with variable extents without any slow-downs.

Ability to jump or animate to specific item

SliverList does not provide any way to jump or animate a particular index. There is a scrollable_positioned_list package that provides this functionality, but it comes at a cost, as it requires custom scroll view, does not seem to work properly with Scrollbars, can't be used with with other slivers (such as sticky headers) and ultimately is backed by a SliverList so it has the same performance issues as mentioned above.

SuperSliverList provides a way to reliably jump and animate to a specific item, even if the item is outside of the viewport and has not been built or laid out yet.

Smooth and predictable scrollbar behavior

SliverList is quite prone to scrollbar erraticaly jumping around when scrolling through a list of items with different extents. With SuperSliverList the scrollbar should behave more predictably. See the Advanced section for more details.

Basic Usage

SuperListView is a drop-in replacement for ListView, and as such you can use it same way you'd use ListView:

SuperListView.builder(
  itemCount: 1000,
  itemBuilder: (context, index) {
    return ListTile(title: Text('Item $index'));
  },
)

SuperSliverList is a drop-in replacement for SliverList and should work with any CustomScrollView configuration:

CustomScrollView(
  slivers: <Widget>[
    SliverPadding(
      padding: const EdgeInsets.all(20.0),
      sliver: SuperSliverList(
        delegate: SliverChildListDelegate(
          <Widget>[
            const Text("I'm dedicating every day to you"),
            const Text('Domestic life was never quite my style'),
            const Text('When you smile, you knock me out, I fall apart'),
            const Text('And I thought I was so smart'),
          ],
        ),
      ),
    ),
  ],
)

Jumping and animating to specific item

ListController can be provided to SuperSliverList/SuperListView and used to jump or animate to specific item:

class _MyState extends State<MyWidget> {
  final _listController = ListController();
  final _scrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return SuperListView.builder(
      listController: _listController,
      controller: _scrollController,
      itemCount: 1000,
      itemBuilder: (context, index) {
        return ListTile(title: Text('Item $index'));
      },
    );
  }

  void jumpToItem(int index) {
    _listController.jumpToItem(
      index: index,
      scrollController: _scrollController,
      alignment: 0.5,
    );
  }

  void animateToItem(int index) {
    _listController.animateToItem(
      index: index,
      scrollController: _scrollController,
      alignment: 0.5,
      // You can provide duration and curve depending on the estimated
      // distance between currentPosition and the target item position.
      duration: (estimatedDistance) => Duration(milliseconds: 250),
      curve: (estimatedDistance) => Curves.easeInOut,
    );
  }
}

Advanced

Very roughtly speaking SuperSliverList works by estimating the extent of items that are outside of viewport and when these items are scrolled into the viewport cache area the scroll position is transparently adjusted to account of the difference between estimated and actual extents. On small lists this difference may result in scrollbar movement not being perfectly aligned with list movement. SuperSliverList provides two ways to rectify this:

Improve extent estimation

You can register custom callback that will be used to estimate extent of estimated items. This can be useful if you have an idea, atleast approximately, how large the extent of each item is.

SuperSliverList(
    delegate: /*...*/,
    estimateExtent: (index) => 100.0, // Provide your own extent estimation
)
Precalculate extents for items

SuperSliverList can, if needed, asynchronously precalculate extents for items. To enfore this, subclass ExtentPrecalculationPolicy and provide it to SuperSliverList:

In this example the extents are eagerly precalculated for lists with less than 100 items:

class MyPrecalculationPolicy extends ExtentPrecalculationPolicy {
  @override
  bool shouldPrecaculateExtents(ExtentPrecalculationContext context)  {
    return context.numberOfItems < 100;
  }
}

return SuperSliverList(
    delegate: /*...*/,
    extentPrecalculationPolicy: myPolicy,
)

The threshold is arbitrary, but in general there are diminishing returns for precalculating extents for large lists, as the extent estimation error for each item has much smaller impact on the scrollbar position if there are many items.

Example

See the example folder for a complete sample app using SuperSliverList. You can also see the example deployed live.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

所在榜單