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

find_dropdown 封面
套件詳情v1.0.0

find_dropdown

簡單且穩健的 FindDropdown,具備項目搜尋功能,可使用離線項目清單或過濾 URL 進行輕鬆自訂。

近 30 天下載
143
喜歡數
82
Pub 分數
70

安裝套件

flutter pub add find_dropdown

套件介紹

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

FindDropdown 是一個輕量且可靠的 Flutter 套件,提供可搜尋的下拉選單元件,讓使用者能從離線清單或遠端 URL 篩選項目。它支援自訂搜尋行為,並能順暢整合至表單或選擇介面中。此套件設計簡潔且具高效能,設定簡單,提供流暢的使用者體驗。適用於需要即時過濾功能的高效項目選擇應用。

適用情境

  • 帶可搜尋選項的表單輸入
  • 離線數據選擇
  • 從URL動態過濾
  • 使用者友善的下拉選單
  • 可自定義的搜尋邏輯

主要特色

  • 即時搜尋功能
  • 支援離線與線上資料來源
  • 輕鬆自訂UI與行為
  • 輕量且高效
  • 內建防抖以提升搜尋效率

適合對象

  • 開發人員建構具有大量選項列表的表單
  • 需要快速、響應迅速的下拉選單的應用
  • 需要離線優先設計的項目
  • 優先考慮簡單整合的團隊

使用建議

  • 需要手動處理非同步資料擷取
  • 有限的內建樣式選項
  • 原生不支援複雜嵌套資料
  • 可能需要額外的驗證來處理邊緣情況
  • 未針對無分頁的極大資料集進行優化

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Buy Me A Coffee

FindDropdown package - [ver em português]

Simple and robust FindDropdown with item search feature, making it possible to use an offline item list or filtering URL for easy customization.

ATTENTION

If you use rxdart in your project in a version lower than 0.23.x, use version 0.1.7+1 of this package. Otherwise, you can use the most current version!

Versions

Null Safety Version: 1.0.0 or more

Non Null Safety Version: 0.2.3 or less

RxDart 0.23.x or less: 0.1.7+1

packages.yaml

find_dropdown: <lastest version>

Import

import 'package:find_dropdown/find_dropdown.dart';

Simple implementation

FindDropdown(
  items: ["Brasil", "Itália", "Estados Unidos", "Canadá"],
  label: "País",
  onChanged: (String item) => print(item),
  selectedItem: "Brasil",
);

Multiple selectable items

FindDropdown<String>.multiSelect(
  items: ["Brasil", "Itália", "Estados Unidos", "Canadá"],
  label: "País",
  onChanged: (List<String> items) => print(items),
  selectedItems: ["Brasil"],
);

Validation

FindDropdown(
  items: ["Brasil", "Itália", "Estados Unidos", "Canadá"],
  label: "País",
  onChanged: (String item) => print(item),
  selectedItem: "Brasil",
  validate: (String item) {
    if (item == null)
      return "Required field";
    else if (item == "Brasil")
      return "Invalid item";
    else
      return null; //return null to "no error"
  },
);

Endpoint implementation (using Dio package)

FindDropdown<UserModel>(
  label: "Nome",
  onFind: (String filter) async {
    var response = await Dio().get(
        "http://5d85ccfb1e61af001471bf60.mockapi.io/user",
        queryParameters: {"filter": filter},
    );
    var models = UserModel.fromJsonList(response.data);
    return models;
  },
  onChanged: (UserModel data) {
    print(data);
  },
);

Clear selected items

var countriesKey = GlobalKey<FindDropdownState>();

Column(
  children: [
    FindDropdown<String>(
      key: countriesKey,
      items: ["Brasil", "Itália", "Estados Unidos", "Canadá"],
      label: "País",
      selectedItem: "Brasil",
      showSearchBox: false,
      onChanged: (selectedItem) => print("country: $selectedItem"),
    ),
    RaisedButton(
      child: Text('Limpar Países'),
      color: Theme.of(context).primaryColor,
      textColor: Theme.of(context).primaryIconTheme.color,
      onPressed: () => countriesKey.currentState?.clear(),
    ),
  ],
)

Change selected items

var countriesKey = GlobalKey<FindDropdownState>();

Column(
  children: [
    FindDropdown<UserModel>(
      label: "Nome",
      onFind: (String filter) => getData(filter),
      searchBoxDecoration: InputDecoration(
        hintText: "Search",
        border: OutlineInputBorder(),
      ),
      onChanged: (UserModel data) {
        print(data);
        countriesKey.currentState.setSelectedItem("Brasil");
      },
    ),
    FindDropdown<String>(
      key: countriesKey,
      items: ["Brasil", "Itália", "Estados Unidos", "Canadá"],
      label: "País",
      selectedItem: "Brasil",
      showSearchBox: false,
      onChanged: (selectedItem) => print("country: $selectedItem"),
    ),
  ],
)
MORE EXAMPLES

Layout customization

You can customize the layout of the FindDropdown and its items. EXAMPLE

To customize the FindDropdown, we have the dropdownBuilder property, which takes a function with the parameters:

  • BuildContext context: current context;
  • T item: Current item, where T is the type passed in the FindDropdown constructor.

To customize the items, we have the dropdownItemBuilder property, which takes a function with the parameters:

  • BuildContext context: current context;
  • T item: Current item, where T is the type passed in the FindDropdown constructor.
  • bool isSelected: Boolean that tells you if the current item is selected.

Attention

To use a template as an item type, you need to implement toString, equals and hashcode, as shown below:

class UserModel {
  final String id;
  final DateTime createdAt;
  final String name;
  final String avatar;

  UserModel({this.id, this.createdAt, this.name, this.avatar});

  @override
  String toString() => name;

  @override
  operator ==(o) => o is UserModel && o.id == id;

  @override
  int get hashCode => id.hashCode^name.hashCode^createdAt.hashCode;

}

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。