搜索插件、代码仓与 APP 分类

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
  • 优先考虑性能和用户体验的团队
  • 使用 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

源码仓库

使用此插件的项目

暂无相关数据。