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

套件詳情v0.1.0

firestore_paging_controller

使用 Firestore 和一些增強功能,懶加載並顯示使用者向下捲動時的項目頁面。

AndroidiOSWebmacOSWindows
近 30 天下載
42
喜歡數
13
Pub 分數
150

安裝套件

flutter pub add firestore_paging_controller

套件介紹

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

一個 Flutter 套件,可實現 Firestore 數據的懶加載分頁形式,透過僅取得可見或附近頁面來提升捲動效能。它簡化了無限捲動的實作,內建狀態管理與錯誤處理。專為與 Firebase Firestore 無縫整合而設計,支援高效資料串流並減少不必要的網路請求。適用於大型資料集清單,例如資訊流、聊天記錄或產品目錄。

適用情境

  • 無限滾動列表
  • 聊天訊息載入中
  • 產品目錄分頁
  • 使用者動態顯示
  • 即時數據流

主要特色

  • Firestore 的懶加載
  • 內建分頁狀態
  • 錯誤與載入狀態
  • 高效能的網路使用
  • 與 ListView 的輕鬆整合
  • 滾動時自動分頁取得

適合對象

  • 大型 Firestore 數據集的應用程式
  • 無限捲動 UI
  • 即時資料顯示
  • 對效能敏感的應用
  • 基於 Firebase 的應用程式

使用建議

  • 需要Firestore設定
  • 僅限 Firestore 數據來源
  • 可能需要自定查詢邏輯
  • 不適合小數據集
  • 依賴互聯網連接

原始 README

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

Firestore Paging Controller

This is a simple Firestore Paging Controller package build on top of the infinite_scroll_pagination package. It provides a simple way to paginate through Firestore collections.

Additionally, it provides a simple way to merge multiple queries into a single stream, which ultimately allows you to have an OR query. On top of that, it also allows ordering the results of the merged queries, which is not possible with Firestore. Internally, it uses the buffer to make sure it doesn't show the items in the wrong order.

Getting Started

To use this package, you need to add the following dependency in your pubspec.yaml file:

dependencies:
  firestore_paging_controller: any

Usage

To use this package, you need to create a FirestorePagingController and (optionally) pass it the queries you want to paginate through. Here is an example:

import 'package:firestore_paging_controller/firestore_paging_controller.dart';

final controller = FirestorePagingController.withoutType(
  basePath: 'posts',
  queryBuilders: [
    (query) => query.where('creatorId', isEqualTo: userId),
    (query) => query.where('taggedUserId', isEqualTo: userId),
  ],
  orderBy: 'createdAt',
  orderByDescending: true,
  pageSize: 10,
);

This will create a controller that will paginate through the items that have the creatorId or taggedUserId equal to the userId. The controller will fetch 10 items per page for each query.

After creating the controller, you can use it in a widget from the infinite_scroll_pagination package. Here is an example:

PagedListView(
  pagingController: controller,
  builderDelegate: PagedChildBuilderDelegate<QueryDocumentSnapshot<Map<String, dynamic>>>(
    itemBuilder: (context, snapshot, index) => Post(snapshot.data()),
  ),
);

If you want to use the type-safe version of the controller, you can do the following:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firestore_paging_controller/firestore_paging_controller.dart';

final controller = FirestorePagingController<PostModel>.converted(
  basePath: 'posts',
  queryBuilders: [
    (query) => query.where('creatorId', isEqualTo: userId),
    (query) => query.where('taggedUserId', isEqualTo: userId),
  ],
  orderBy: 'createdAt',
  orderByDescending: true,
  pageSize: 10,
  fromMap: (data) => PostModel.fromMap(data),
);

Then it can be used like this:

PagedListView<int, QueryDocumentSnapshot<T>>(
  pagingController: controller,
  builderDelegate: PagedChildBuilderDelegate<QueryDocumentSnapshot<T>>(
    itemBuilder: (context, snapshot, index) => Post(snapshot.data()),
  ),
);

Reminders:

  • The queries you pass to the controller should not have any limit or orderBy applied to them.
  • You may need to create an index in Firestore for the queries you are using in the controller. Look at the logs for the error message and create the index accordingly.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。