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

插件详情v2.0.2

flappy_search_bar_ns

SearchBar 小部件可自动处理大多数异步搜索场景。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
896
喜欢数
29
Pub 分数
120

安装插件

flutter pub add flappy_search_bar_ns

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

FlappySearchBarNS 是一个专为简化异步搜索实现而设计的 Flutter 小部件。它自动化了常见的搜索工作流程,包括处理用户输入、管理加载状态以及从异步数据源显示结果。专为希望在多个平台上实现流畅搜索功能的开发者打造,该组件可无缝集成到现有的搜索 API 中,并支持实时过滤。通过抽象搜索逻辑中的重复模式,该包减少了样板代码,非常适合需要动态、响应式搜索体验的应用程序。

适合场景

  • 实时搜索与异步数据
  • 筛选大型数据集
  • 移动和网页应用中的搜索 UI
  • 动态内容发现
  • 实现自动补全功能
  • 跨平台搜索组件

主要特点

  • 自动异步搜索处理
  • 内置的加载和错误状态
  • 支持实时输入处理
  • 跨平台兼容性
  • 所需的最小样板
  • 可自定义的结果显示

适合对象

  • 开发搜索密集型应用的开发者
  • 优先考虑快速UI开发的团队
  • 针对多个平台的项目
  • 需要响应式搜索用户体验的应用
  • Flutter 初学者学习搜索模式

使用建议

  • 需要理解异步操作
  • 可能需要为复杂 UI 添加自定义样式
  • 有限的内置过滤器,仅限基本文本匹配
  • 依赖外部 API 集成
  • 未针对极高频率的搜索查询进行优化

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flappy_search_bar_ns

A SearchBar widget handling most of search cases.

Usage

To use this plugin, add flappy_search_bar_ns as a dependency in your pubspec.yaml file.

Example
@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SearchBar<Post>(
          searchBarPadding: EdgeInsets.symmetric(horizontal: 10),
          headerPadding: EdgeInsets.symmetric(horizontal: 10),
          listPadding: EdgeInsets.symmetric(horizontal: 10),
          onSearch: _getALlPosts,
          searchBarController: _searchBarController,
          placeHolder: Text("placeholder"),
          cancellationWidget: Text("Cancel"),
          emptyWidget: Text("empty"),
          indexedScaledTileBuilder: (int index) => ScaledTile.count(1, index.isEven ? 2 : 1),
          header: Row(
            children: <Widget>[
              RaisedButton(
                child: Text("sort"),
                onPressed: () {
                  _searchBarController.sortList((Post a, Post b) {
                    return a.body.compareTo(b.body);
                  });
                },
              ),
              RaisedButton(
                child: Text("Desort"),
                onPressed: () {
                  _searchBarController.removeSort();
                },
              ),
              RaisedButton(
                child: Text("Replay"),
                onPressed: () {
                  isReplay = !isReplay;
                  _searchBarController.replayLastSearch();
                },
              ),
            ],
          ),
          onCancelled: () {
            print("Cancelled triggered");
          },
          mainAxisSpacing: 10,
          crossAxisSpacing: 10,
          crossAxisCount: 2,
          onItemFound: (Post post, int index) {
            return Container(
              color: Colors.lightBlue,
              child: ListTile(
                title: Text(post.title),
                isThreeLine: true,
                subtitle: Text(post.body),
                onTap: () {
                  Navigator.of(context).push(MaterialPageRoute(builder: (context) => Detail()));
                },
              ),
            );
          },
        ),
      ),
    );
  }
Try it

A sample app is available to let you try all the features ! :)

Warning

If you want to use a SearchBarController in order to do some sorts or filters, PLEASE put your instance of SearchBarController in a StateFullWidget.

If not, it will not work properly.

If you don't use an instance of SearchBarController, you can keep everything in a StateLessWidget !

Parameters
Name Type Usage Required Default Value
onSearch Future<List> Function(String text) Callback giving you the text to look for and asking for a Future yes -
onItemFound Widget Function(T item, int index) Callback letting you build the widget corresponding to each item yes -
suggestions List Potential fist list of suggestions (when no request have been made) no []
searchBarController SearchBarController Enable you to sort and filter your list no default controller
searchBarStyle SearchBarStyle Syle to customize SearchBar no default values on bottom tab
buildSuggestions Widget Function(T item, int index) Callback called to let you build Suggestion item (if not provided, the suggestion will have the same layout as the basic item) no null
minimumChars int Minimum number of chars to start querying no 3
onError Function(Error error) Callback called when an error occur runnning Future no null
debounceDuration Duration Debounce's duration no Duration(milliseconds: 500)
loader Widget Widget that appears when Future is running no CircularProgressIndicator()
emptyWidget Widget Widget that appears when Future is returning an empty list no SizedBox.shrink()
icon Widget Widget that appears on left of the SearchBar no Icon(Icons.search)
hintText String Hint Text no ""
hintStyle TextStyle Hint Text style no TextStyle(color: Color.fromRGBO(142, 142, 147, 1))
iconActiveColor Color Color of icon when active no Colors.black
textStyle TextStyle TextStyle of searched text no TextStyle(color: Colors.black)
cancellationWidget Widget Widget shown on right of the SearchBar no Text("Cancel")
onCancelled VoidCallback Callback triggered on cancellation's button click no null
crossAxisCount int Number of tiles on cross axis (Grid) no 2
shrinkWrap bool Wether list should be shrinked or not (take minimum space) no true
scrollDirection Axis Set the scroll direction no Axis.vertical
mainAxisSpacing int Set the spacing between each tiles on main axis no 10
crossAxisSpacing int Set the spacing between each tiles on cross axis no 10
indexedScaledTileBuilder IndexedScaledTileBuilder Builder letting you decide how much space each tile should take no (int index) => ScaledTile.count(1, index.isEven ? 2 : 1)
searchBarPadding EdgeInsetsGeometry Set a padding on the search bar no EdgeInsets.symmetric(horizontal: 10)
headerPadding EdgeInsetsGeometry Set a padding on the header no EdgeInsets.symmetric(horizontal: 10)
listPadding EdgeInsetsGeometry Set a padding on the list no EdgeInsets.symmetric(horizontal: 10)
SearchBar default SearchBarStyle
Name Type default Value
backgroundColor Color Color.fromRGBO(142, 142, 147, .15)
padding EdgeInsetsGeometry EdgeInsets.all(5.0)
borderRadius BorderRadius BorderRadius.all(Radius.circular(5.0))})

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目