firestore_paging_controller
사용자가 화면을 아래로 스크롤할 때 지연 로드하여 항목 페이지를 표시하고, Firestore와 일부 개선 사항을 사용합니다.
StageCoding/firestore_paging_controller open-source repository details.
{"sdk":"flutter"}^4.1.0^5.6.0{"sdk":"flutter"}^4.0.0^5.4.5^1.25.8^2.4.14^6.6.0^3.9.0아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
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.
To use this package, you need to add the following dependency in your pubspec.yaml file:
dependencies:
firestore_paging_controller: any
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()),
),
);