パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.1.0

firestore_paging_controller

ユーザーが画面を下にスクロールする際に、Firestore を使ってアイテムのページを遅延読み込みして表示します。いくつかの改善も含まれます。

AndroidiOSWebmacOSWindows
30日間ダウンロード
42
いいね数
13
Pub ポイント
150

パッケージをインストール

flutter pub add firestore_paging_controller

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

ページ単位でFirestoreデータを遅延読み込みできるFlutterパッケージで、表示中または近接するページのみを取得することでスクロールパフォーマンスを向上させます。組み込みの状態管理とエラー処理により、無限スクロールの実装が簡単になります。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 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。