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

flutter_pagewise のカバー
パッケージ詳細v2.0.4

flutter_pagewise

コンテンツを1ページ(またはバッチ)ずつ読み込むためのウィジェット用ライブラリです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
4710
いいね数
208
Pub ポイント
140

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

flutter pub add flutter_pagewise

パッケージ概要

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

flutter_pagewise は、アプリケーションにおけるページネートされたコンテンツの実装を簡素化することを目的とした Flutter パッケージです。データをバッチまたはページ単位で読み込むウィジェットを提供しており、パフォーマンスに負担をかけずに大規模なデータセットを効率的に処理するのに適しています。このパッケージは、プルツーリフレッシュと無限スクロールの両方をサポートしており、リストやグリッド、その他のスクロール可能なインターフェースに最適です。任意のデータソースとシームレスに統合でき、Android、iOS、Web、macOS、Windows、Linux などの主要プラットフォームで動作します。

用途

  • 無限スクロールリスト
  • 遅延読み込みデータ
  • プルトゥリフレッシュページネーション
  • 大規模データセットのレンダリング
  • 動的コンテンツの取得
  • グリッドベースのページネーション表示

主な機能

  • 自動ページロード
  • 組み込みのリフレッシュサポート
  • クロスプラットフォーム互換性
  • カスタマイズ可能な読み込みインジケーター
  • 柔軟なデータソース統合
  • 垂直および水平スクロールをサポートしています

適している対象

  • 大規模なデータセットを持つアプリケーション
  • ソーシャルメディアフィード
  • EC商品リスト
  • ニュースやブログのコンテンツ
  • 効率的なデータ読み込みを必要とするアプリ

注意事項

  • 適切なエラー処理が必要です
  • 慎重な状態管理が必要です
  • カスタムキャッシュ戦略が必要になる場合があります
  • 小さなデータセットには適していない
  • 外部データソースに依存しています
  • パフォーマンスはネットワーク速度によって異なります

元の 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 件

ソースリポジトリ

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

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