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

flutter_pagewise 표지
패키지 상세v2.0.4

flutter_pagewise

내용을 한 페이지(또는 배치)씩 차례로 로드하는 위젯을 위한 라이브러리입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
4.7천
좋아요
208
Pub 점수
140

패키지 설치

flutter pub add flutter_pagewise

패키지 개요

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

flutter_pagewise는 앱에서 페이지 기반 콘텐츠를 구현하는 것을 간소화하도록 설계된 Flutter 패키지입니다. 데이터를 배치 또는 페이지 단위로 로드할 수 있는 위젯을 제공하여 성능에 부담을 주지 않으면서도 대규모 데이터 세트를 효율적으로 처리할 수 있습니다. 이 패키지는 하단에서 새로 고침 및 무한 스크롤을 모두 지원하며, 리스트, 그리드 및 기타 스크롤 가능한 인터페이스에 적합합니다. 어떤 데이터 소스와도 원활하게 통합되며 Android, iOS, Web, macOS, Windows, Linux 등 주요 플랫폼에서 작동합니다.

사용 사례

  • 무한 스크롤 목록
  • 지연로딩 데이터
  • 풀투리프레시 페이징
  • 대규모 데이터셋 렌더링
  • 동적 콘텐츠 가져오기
  • 기반 그리드 기반의 페이지 표시

주요 기능

  • 자동 페이지 로드
  • 내장된 새로 고침 지원
  • 크로스 플랫폼 호환성
  • 사용자 정의 가능한 로딩 인디케이터
  • 유연한 데이터 소스 통합
  • 수직 및 수평 스크롤을 모두 지원합니다

적합한 대상

  • 대규모 데이터셋을 가진 앱
  • 소셜 미디어 피드
  • 전자상거래 제품 목록
  • 뉴스 또는 블로그 콘텐츠
  • 효율적인 데이터 로딩이 필요한 모든 앱

고려 사항

  • 적절한 오류 처리가 필요합니다
  • 신중한 상태 관리가 필요합니다
  • 사용자 정의 캐싱 전략이 필요할 수 있습니다
  • 작은 데이터 세트에 적합하지 않음
  • 외부 데이터 소스에 의존
  • 성능은 네트워크 속도에 따라 달라집니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

A library for widgets that load their content one page (or batch) at a time (also known as lazy-loading and pagination).

flutter_pagewise

Features

  • Load data one page at a time
  • Retry failed pages
  • Override the default loading, retry, and error widgets if desired
  • Manage loading of data more closely using a PagewiseLoadController
  • ListView and GridView implementations
  • SliverList and SliverGrid implementations
  • Extendability using inheritance

Breaking Change Starting V1.0.0:

The library has been rewritten in version 1.0.0 to provide a more efficient implementation that does not require a totalCount parameter and shows only one loading sign when users scroll down. In addition, a new parameter has been added to itemBuilder callback to provide the index if needed by the user.

Installing the library:

Like any other package, add the library to your pubspec.yaml dependencies:

dependencies:
    flutter_pagewise:

Then import it wherever you want to use it:

import 'package:flutter_pagewise/flutter_pagewise.dart';

Using the library

Check out the example

The library provides the following widgets:

  • PagewiseGridView: A pagewise implementation of GridView. It could be used as follows:
PagewiseGridView.count(
  pageSize: 10,
  crossAxisCount: 2,
  mainAxisSpacing: 8.0,
  crossAxisSpacing: 8.0,
  childAspectRatio: 0.555,
  padding: EdgeInsets.all(15.0),
  itemBuilder: (context, entry, index) {
    // return a widget that displays the entry's data
  },
  pageFuture: (pageIndex) {
    // return a Future that resolves to a list containing the page's data
  },
);
  • PagewiseListView: A pagewise implementation of ListView. It could be used as follows:
PagewiseListView(
  pageSize: 10,
  padding: EdgeInsets.all(15.0),
  itemBuilder: (context, entry, index) {
    // return a widget that displays the entry's data
  },
  pageFuture: (pageIndex) {
    // return a Future that resolves to a list containing the page's data
  }
);
  • PagewiseSliverGrid: A pagewise implementation of SliverGrid. It could be used similar to PagewiseGridView for cases where a sliver is needed.
  • PagewiseSliverList: A pagewise implementation of SliverList. It could be used similar to PagewiseListView for cases where a sliver is needed.

The classes provide all the properties of ListViews and GridViews. In addition, you must provide the itemBuilder, which tells Pagewise how you want to render each element, and pageFuture, which Pagewise calls to fetch new pages. Please note that pageFuture must not return more values than mentioned in the pageSize parameter.

Customizing the widget:

In addition to the required parameters, Pagewise provides you with optional parameters to customize the widget. You have loadingBuilder, errorBuilder, noItemsFoundBuilder, and retryBuilder to customize the widgets that show on loading, error, no found items and retry respectively.

The loadingBuilder can be used as follows:

loadingBuilder: (context) {
  return Text('Loading...');
}

The noItemsFoundBuilder can be used as follows:

noItemsFoundBuilder: (context) {
  return Text('No Items Found');
}

The retryBuilder can be used as follows:

retryBuilder: (context, callback) {
  return RaisedButton(
    child: Text('Retry'),
    onPressed: () => callback()
  );
}

Thus, the retryBuilder provides you with a callback that you can call when you want to retry.

The errorBuilder is only relevant when showRetry is set to false, because, otherwise, the retryBuilder is shown instead. The errorBuilder can be used as follows:

errorBuilder: (context, error) {
  return Text('Error: $error');
}

Check the classes' documentation for more details.

Providing your own PagewiseLoadController:

Pagewise widgets manage the loading of pages using a PagewiseLoadController. This controller is responsible for fetching data, handling errors, etc.

You don't have to provide a controller yourself when creating a Pagewise widget. The widget will create one for you. However you might wish to create one yourself in order to achieve some effects.

Notice though that if you provide a controller yourself, you should provide the [pageFuture] and [pageSize] parameters to the controller instead of the widget.

A possible use case of the controller is to force a reset of the loaded pages using a RefreshIndicator. you could achieve that as follows (note that we added the Future.value({}) as a dummy return value, because onRefresh expects a Future, but reset does not return one):

final _pageLoadController = PagewiseLoadController(
  pageSize: 6,
  pageFuture: BackendService.getPage
);

@override
Widget build(BuildContext context) {
  return RefreshIndicator(
    onRefresh: () async {
      this._pageLoadController.reset();
      await Future.value({});
    },
    child: PagewiseListView(
        itemBuilder: this._itemBuilder,
        pageLoadController: this._pageLoadController,
    ),
  );
}

Another use case for creating the controller yourself is if you want to listen to the state of Pagewise and act accordingly. For example, you might want to show a snackbar when we reach the end of the list In that case, you could do:

final _pageLoadController = PagewiseLoadController(
  pageSize: 6,
  pageFuture: BackendService.getPage
);

@override
void initState() {
  super.initState();
  this._pageLoadController.addListener(() {
    if (!this._pageLoadController.hasMoreItems) {
      Scaffold.of(context).showSnackBar(
        SnackBar(
          content: Text('No More Items!')
        )
      );
    }
  });
}

Creating your own Pagewise Widgets:

You need to inherit from the Pagewise class. Check the code of PagewiseListView and PagewiseGridView for examples

카테고리

의존성

의존성 목록 1 개

소스 저장소

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

아직 데이터가 없습니다.