搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。