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

套件詳情v1.0.0

incrementally_loading_listview

列表視圖組件的擴展,可在捲動時逐步加載資料

近 30 天下載
218
喜歡數
46
Pub 分數
40

安裝套件

flutter pub add incrementally_loading_listview

套件介紹

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

一個 Flutter 套件,擴展 ListView 小工具以在捲動時實現增量資料載入。當使用者接近清單結尾時,它會自動觸發資料擷取,非常適合處理大型資料集而不會影響效能。該套件透過無縫管理捲動事件和載入狀態來簡化分頁邏輯。支援自訂載入指示器和錯誤處理,確保順暢的使用者體驗。專為尋求高效、開箱即用的懶加載且需最少樣板程式碼的開發者設計。

適用情境

  • 即時載入大型資料集
  • 實現無限滾動資訊流
  • 獲取分頁 API 結果
  • 構建聊天或時間線介面
  • 在長列表中提升效能

主要特色

  • 自動滾動資料加載
  • 可自定義的載入指示器
  • 內建錯誤處理
  • 與現有 ListView 的簡單整合
  • 支援正向與反向分頁

適合對象

  • 開發動態內容提要的開發者
  • 包含大量數據列表的應用程式
  • 需要流暢滾動性能的項目
  • 希望減少分頁樣板程式碼的團隊
  • 依賴網路的資料移動應用

使用建議

  • 需要正確的狀態管理
  • 可能需要針對複雜的載入邏輯進行自訂
  • 未針對極高頻率的更新進行優化
  • 有限的平台特定優化
  • 依賴外部相依性以實現完整功能

原始 README

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

incrementally_loading_listview

pub package

An extension of the Flutter ListView widget for incrementally loading items upon scrolling. This could be used to load paginated data received from API requests.

NOTE: this package depends on rxdart. If you run into conflicts with different versions of rxdart, consider using dependency overrides as per this link

Getting Started

There's a working example that can be run to see how it works.

First import the library

import 'package:incrementally_loading_listview/incrementally_loading_listview.dart';

You can then use the IncrementallyLoadingListView widget in a similar way you would with the ListView.separated constructor

return IncrementallyLoadingListView(
    hasMore: () => _hasMoreItems,
    itemCount: () => items.length,
    loadMore: () async {
        // can shorten to "loadMore: _loadMoreItems" but this syntax is used to demonstrate that
        // functions with parameters can also be invoked if needed
        await _loadMoreItems();
    },
    loadMoreOffsetFromBottom: 2,
    itemBuilder: (context, index) {
        /// your builder function for rendering the item
    },
    separatorBuilder: (context, index) {
        /// your builder function for rendering the separator
    }
);

The widget allows passing in the same parameters you would to the ListView.builder constructor but itemCount is required so that when an item scrolls into view, it can see if it should attempt to load more items. Note that this is a callback that returns a boolean rather than being a boolean value. This allows the widget to not require a reference/copy of your data collection. The other parameters that can be specified are

  • hasMore: a callback that indicates if there are more items that can be loaded
  • loadMore: a callback to an asynchronous function that loads more items
  • loadMoreOffsetFromBottom: determines when the list view should attempt to load more items based on of the index of the item is scrolling into view. This is relative to the bottom of the list and has a default value of 0 so that it loads when the last item within the list view scrolls into view. As an example, setting this to 1 would attempt to load more items when the second last item within the list view scrolls into view
  • onLoadMore: a callback that is triggered when more items are being loaded. At first this will pass a boolean value of true to when items are being loaded by triggering the loadMore callback function. You could use this to update your UI to show a loading indicator
  • onLoadMoreFinished: a callback that is triggered when items have finished being loading. You can use this to hide your loading indicator
  • separatorBuilder: not required builder function that place separator between items

Providing onLoadMore and onLoadMoreFinished callbacks means the widget doesn't make assumptions on how you want to render a loading indicator so it will be up to your application to handle these callbacks to render the appropriate UI.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。