搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。