패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.1.0

firestore_paging_controller

사용자가 화면을 아래로 스크롤할 때 지연 로드하여 항목 페이지를 표시하고, Firestore와 일부 개선 사항을 사용합니다.

AndroidiOSWebmacOSWindows
30일 다운로드
42
좋아요
13
Pub 점수
150

패키지 설치

flutter pub add firestore_paging_controller

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

페이지 단위로 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.