搜尋套件、儲存庫與 APP 分類

paginated_search_bar 封面
套件詳情v1.1.2

paginated_search_bar

一個搜尋欄庫,讓您可以在結果清單中搜尋項目並分頁。

近 30 天下載
41
喜歡數
52
Pub 分數
60

安裝套件

flutter pub add paginated_search_bar

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供內建分頁功能的搜尋欄,用於顯示搜尋結果。它讓使用者能夠輸入查詢並分頁瀏覽結果,當處理大量資料時,可提升效能與使用者體驗。此套件可處理非同步搜尋作業,並以最少設定順暢整合至現有介面。支援自訂結果顯示與載入狀態,非常適合需要高效、可擴展搜尋功能的應用程式。

適用情境

  • 高效搜尋大型資料集
  • 實現分頁搜尋結果
  • 在資料密集型應用中提升使用者體驗
  • 建構動態搜尋介面
  • 與遠端 API 集成以進行搜尋
  • 減少搜尋過程中的記憶體使用

主要特色

  • 內建分頁支援
  • 非同步搜尋處理
  • 可自訂的結果UI
  • 加載和錯誤狀態管理
  • 與現有小部件的輕鬆整合
  • 支援遠端和本機資料來源

適合對象

  • 開發搜尋密集型應用的開發者
  • 包含大型數據集的應用程式
  • 需要平滑滾動和懶加載的 UI
  • 優先考慮效能和使用者體驗的團隊
  • 使用 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

原始碼儲存庫

使用此套件的專案

暫無相關資料。