搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案