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

paginated_search_bar のカバー
パッケージ詳細v1.1.2

paginated_search_bar

アイテムを検索して結果リストでページングできる検索バーのライブラリです。

30日間ダウンロード
41
いいね数
52
Pub ポイント
60

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

flutter pub add paginated_search_bar

パッケージ概要

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

検索結果を表示するための組み込みページネーション機能付きの検索バーを提供するFlutterパッケージです。ユーザーがクエリを入力し、ページ単位で結果をナビゲートできるようにし、大規模なデータセットを扱う際のパフォーマンスとユーザーエクスペリエンスを向上させます。このライブラリは非同期検索操作を処理し、最小限の設定で既存のUIにスムーズに統合されます。カスタマイズ可能な結果表示およびロード状態をサポートしており、効率的でスケーラブルな検索機能を必要とするアプリに最適です。

用途

  • 大規模なデータセットを効率的に検索する
  • ページネーションされた検索結果の実装
  • データが多く含まれるアプリでのユーザーエクスペリエンスの向上
  • 動的検索インターフェースの構築
  • 検索用のリモートAPIとの統合
  • 検索中のメモリ使用量の削減

主な機能

  • 組み込みのページネーションサポート
  • 非同期検索処理
  • カスタマイズ可能な結果UI
  • 読み込みとエラー状態の管理
  • 既存のウィジェットとの簡単な統合
  • リモートおよびローカルデータソースのサポート

適している対象

  • 検索中心のアプリを開発する開発者
  • 大規模なデータセットを備えたアプリ
  • スムーズなスクロールと遅延読み込みを必要とする UI
  • パフォーマンスとUXを重視するチーム
  • REST または GraphQL API を使用するプロジェクト
  • Flutterの初心者がページネーションパターンを学習しています

注意事項

  • 検索ロジックの実装が必要です
  • 基本的な検索UIカスタマイズに限定
  • 組み込みのフィルタリングや並べ替えなし
  • 外部データソースに依存しています
  • 複雑なデザインには追加のスタイリングが必要になる場合があります
  • デバウンスなしでリアルタイム検索に最適化されていません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Paginated Search Bar

A search bar library that let's you search for items and paginate them in a results list. By default it looks like this:

Basic demo gif.

It supports extensive customization with custom styling, headers, placeholders, footers and more powered by the Endless infinite scroll view library.

Advanced demo gif

Usage

class ExampleItem {
  final String title;

  ExampleItem({
    required this.title,
  });
}

PaginatedSearchBar<ExampleItem>(
  onSearch: ({
    required pageIndex,
    required pageSize,
    required searchQuery,
  }) async {
    // Call your search API to return a list of items
    return [
      ExampleItem(title: 'Item 0'),
      ExampleItem(title: 'Item 1'),
    ];
  },
  itemBuilder: (
    context, {
    required item,
    required index,
  }) {
    return Text(item.title);
  },
);

In this basic usage, all you need to get started is an onSearch function for fetching data and an itemBuilder for how it should be displayed in the search results list.

Advanced Usage

PaginatedSearchBar<ExampleItem>(
  maxHeight: 300,
  hintText: 'Search',
  headerBuilderState: PaginatedSearchBarBuilderStateProperty.empty((context) {
    return const Text("I'm a header that only shows when the results are empty!");
  }),
  emptyBuilder: (context) {
    return const Text("I'm an empty state!");
  },
  paginationDelegate: EndlessPaginationDelegate(
    pageSize: 20,
    maxPages: 3,
  ),
  onSearch: ({
    required pageIndex,
    required pageSize,
    required searchQuery,
  }) async {
    return Future.delayed(const Duration(milliseconds: 1000), () {
      if (searchQuery == "empty") {
        return [];
      }

      return [
        ExampleItem(title: 'Page $pageIndex item 1'),
        ExampleItem(title: 'Page $pageIndex item 2'),
      ];
    });
  },
  itemBuilder: (
    context, {
    required item,
    required index,
  }) {
    return Text(item.title);
  },
);

In this more advanced example, we've provided a few more customization options including an emptyBuilder and headerBuilderState. All of the builder functions like emptyBuilder provide the current BuildContext and return a widget to display. Each builder function additionally has a corresponding StateProperty builder like we see with headerBuilderState. The PaginatedSearchBar library uses the State property pattern for customizing the display of the widget based on the state of the system.

The complete list of paginated search bar states are:

enum PaginatedSearchBarState {
  /// Present when the search bar is searching for items. Triggered when they update their search
  /// query in the input.
  searching,

  /// Present when the search bar is fetching a page of items either as a result of a modified search query
  /// or by scrolling to the bottom of the list view and triggering the next page load.
  loading,

  /// Present when the search bar has no matching items for the current search query.
  empty,

  /// Present when the search bar has no more items to fetch for the current search query. Triggered
  /// when the [PaginatedSearchBar.onSearch] function returns fewer than [PaginatedSearchBar.pageLimit]
  /// items or [EndlessPaginationDelegate.maxPage] has been reached and no more items can be fetched.
  done,

  /// Present the input is currently focused.
  focused,
}

State properties builders then let us customize what we build based on these states. In the above example with headerBuilderState, we specified that it should only build the widget when the search results are empty.

If we instead wanted it show be shown when the search results are empty or done, we could use the state property resolveWith builder:

PaginatedSearchBar<ExampleItem>(
  headerBuilderState: PaginatedSearchBarBuilderStateProperty.resolveWith((context, states) {
    if (states.contain(PaginatedSearchBarState.empty) || states.contain(PaginatedSearchBarState.done)) {
      return const Text("I'm a header that only shows when the results are empty or done!");
    }
  }),
  onSearch: ({
    required pageIndex,
    required pageSize,
    required searchQuery,
  }) async {
    return Future.delayed(const Duration(milliseconds: 1000), () {
      if (searchQuery == "empty") {
        return [];
      }

      return [
        ExampleItem(title: 'Page $pageIndex item 1'),
        ExampleItem(title: 'Page $pageIndex item 2'),
      ];
    });
  },
  itemBuilder: (
    context, {
    required item,
    required index,
  }) {
    return Text(item.title);
  },
);

The state properties are available for builders and style properties of the [PaginatedSearchBar].

Feedback

Let us know if there are any additional features or customization options you'd like to see to make a helpful search bar.

カテゴリー

依存関係

依存関係一覧 3 件

  • endless^1.5.2
  • rxdart^0.27.2
  • state_property^1.1.1

ソースリポジトリ

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

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