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

插件详情v1.0.6+1

easy_search

一个高度可定制的搜索组件,可加速您的开发。

近 30 天下载
15
喜欢数
72
Pub 分数
40

安装插件

flutter pub add easy_search

插件介绍

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

Easy Search 是一个高度可定制的搜索组件,旨在通过提供灵活且可重复使用的搜索界面来简化开发。它基于 Flutter 构建,开箱即用地提供了列表过滤、实时输入处理以及各种 UI 自定义功能。适用于需要快速、直观搜索体验的应用程序,可减少样板代码并加速功能实现。该包可无缝集成到现有项目中,并支持跨平台的响应式设计。

适合场景

  • 实现动态列表过滤
  • 创建可搜索的下拉菜单
  • 构建即时搜索界面
  • 增强大型数据集中的用户导航
  • 向表单添加搜索功能

主要特点

  • 实时搜索输入处理
  • 可自定义的用户界面和样式
  • 支持异步和同步过滤
  • 可重用的搜索小部件
  • 轻量且易于集成

适合对象

  • 寻求快速搜索实现的开发者
  • 需要筛选大型数据集的应用程序
  • 需要一致搜索组件的UI密集型应用程序
  • 注重开发速度和可维护性的团队

使用建议

  • 需要手动设置以实现复杂的过滤逻辑
  • 对高级搜索功能(如模糊匹配)的内置支持有限
  • 未提及平台特定优化
  • 依赖外部状态管理来处理复杂用例

原始 README

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

logo

A highly customizable search component to accelerate your development.

Pub Package Buy Me A Coffee

Overview

There are many search or search components for Flutter, however this one comes to perform search in Offline List,

or HTTP Search and more, it already comes with nice default layout and many customizations,

and we can focus more on writing amazing applications.

Contributing
Getting Started

In pubspec.yaml:

dependencies:
  easy_search: any
Important configuration:
  • If you want to use the Offline List or Local list, do not implement the OnSearch method

  • If you want to fetch data from a web server or an API, do not implement the Offline List or Local List

  • If both OnSearch and the Offline List are implemented, the OnSearch method will prevail and the Offline List will be ignored
Offline list:
Default Layout:
Simple Offline List
import 'package:easy_search/easy_search.dart';

EasySearch(
  searchResultSettings: SearchResultSettings(
    padding: EdgeInsets.only(left: 8.0, top: 8.0, right: 8.0),
  ),
  controller: SearchItem(
    items: [
      Item(ModelExample(name: 'Tiago', age: 36), false),
      Item(ModelExample(name: 'Mel', age: 3), false),
      Item(ModelExample(name: 'Monique', age: 30), false),
    ],
  ),
),
Custom Layout:
Simple Offline List With Custom Layout
import 'package:easy_search/easy_search.dart';

EasySearch(
  searchResultSettings: SearchResultSettings(
    padding: EdgeInsets.only(left: 8.0, top: 8.0, right: 8.0),
  ),
  controller: SearchItem(
    items: [
      Item(ModelExample(name: 'Tiago', age: 36), false),
      Item(ModelExample(name: 'Mel', age: 3), false),
      Item(ModelExample(name: 'Monique', age: 30), false),
    ],
  ),
  customItemBuilder: (BuildContext context, ModelExample item, bool isSelected) {
    return Container(
      decoration: !isSelected
          ? null
          : BoxDecoration(
              border: Border.all(color: Theme.of(context).primaryColor),
              borderRadius: BorderRadius.circular(7),
              color: Colors.white,
            ),
      child: ListTile(
        selected: isSelected,
        title: Text(item.name),
        subtitle: Text(
          item.age.toString(),
        ),
        leading: Icon(Icons.people),
      ),
    );
  },
),
Multi Select Items:
Simple Offline List With Custom Layout And Multi Selection Items
import 'package:easy_search/easy_search.dart';

EasySearch(
  multipleSelect: true,
  searchResultSettings: SearchResultSettings(padding: EdgeInsets.only(left: 8.0, top: 8.0, right: 8.0)),
  controller: SearchItem(
    items: [
      Item(ModelExample(name: 'Tiago', age: 36), false),
      Item(ModelExample(name: 'Mel', age: 3), false),
      Item(ModelExample(name: 'Monique', age: 30), false),
    ],
  ),
  customItemBuilder: (BuildContext context, ModelExample item, bool isSelected) {
    return Container(
      decoration: !isSelected
          ? null
          : BoxDecoration(
              border: Border.all(color: Theme.of(context).primaryColor),
              borderRadius: BorderRadius.circular(7),
              color: Colors.white,
            ),
      child: ListTile(
        selected: isSelected,
        title: Text(item.name),
        subtitle: Text(item.age.toString()),
        leading: Icon(Icons.people),
      ),
    );
  },
),
HTTP Request:
Default Layout - Http:
From HTTP Request
import 'package:easy_search/easy_search.dart';

EasySearch(
  onSearch: (text) {
    print('Filter Query: $text');
    return getData(name: text);
  },
  searchResultSettings: SearchResultSettings(
    padding: EdgeInsets.only(left: 8.0, top: 8.0, right: 8.0),
  ),
),

.
.
.

//HTTP request Example
Future<List<ModelExample>> getData({name}) async {
  var response = await Dio().get(
    "https://5f24717b3b9d35001620456b.mockapi.io/user",
    queryParameters: {"name": name},
  );

  var result = ModelExample.fromJsonList(response.data);
  return result;
}
Custom Layout - Http:
From HTTP Request With Custom Layout
import 'package:easy_search/easy_search.dart';

EasySearch(
onSearch: (text) {
  print('Filter Query: $text');
  return getData(name: text);
},
searchResultSettings: SearchResultSettings(
  padding: EdgeInsets.only(left: 8.0, top: 8.0, right: 8.0),
),
customItemBuilder: (BuildContext context, ModelExample item, bool isSelected) {
  return Container(
    decoration: !isSelected
        ? null
        : BoxDecoration(
            border: Border.all(color: Theme.of(context).primaryColor),
            borderRadius: BorderRadius.circular(7),
            color: Colors.white,
          ),
    child: ListTile(
      selected: isSelected,
      title: Text(item.name),
      subtitle: Text(item.age.toString()),
      leading: Icon(Icons.people),
    ),
  );
},
),

.
.
.

//HTTP request Example
Future<List<ModelExample>> getData({name}) async {
  var response = await Dio().get(
    "https://5f24717b3b9d35001620456b.mockapi.io/user",
    queryParameters: {"name": name},
  );

  var result = ModelExample.fromJsonList(response.data);
  return result;
}
Multi Select Items - Http:
From HTTP Request With Custom Layout And Multi Select Items
import 'package:easy_search/easy_search.dart';

EasySearch(
multipleSelect: true,
onSearch: (text) {
  print('Filter Query: $text');
  return getData(name: text);
},
searchResultSettings: SearchResultSettings(
  padding: EdgeInsets.only(left: 8.0, top: 8.0, right: 8.0),
),
customItemBuilder: (BuildContext context, ModelExample item, bool isSelected) {
  return Container(
    decoration: !isSelected
        ? null
        : BoxDecoration(
            border: Border.all(color: Theme.of(context).primaryColor),
            borderRadius: BorderRadius.circular(7),
            color: Colors.white,
          ),
    child: ListTile(
      selected: isSelected,
      title: Text(item.name),
      subtitle: Text(item.age.toString()),
      leading: Icon(Icons.people),
    ),
  );
},
),

.
.
.

//HTTP request Example
Future<List<ModelExample>> getData({name}) async {
  var response = await Dio().get(
    "https://5f24717b3b9d35001620456b.mockapi.io/user",
    queryParameters: {"name": name},
  );

  var result = ModelExample.fromJsonList(response.data);
  return result;
}
Programmatically changing the Item List:
Programmatically changing the Item List
import 'package:easy_search/easy_search.dart';

EasySearch(
  onSearch: (text) {
    print('Filter Query: $text');
    return getData(name: text);
  },
  startWithValue: true,
  searchResultSettings: SearchResultSettings(
    padding: EdgeInsets.only(left: 8.0, top: 8.0, right: 8.0),
    label: LabelSettings.searchLabel(value: 'People'),
  ),
  filterPageSettings: FilterPageSettings(
    searchOnShow: false,
  ),
  controller: controllerStartWithValue,
),
Center(
  child: RaisedButton(
    onPressed: () {
      //1ª Create the new listToFill
      List<Item<ModelExample>> listToFill = [
        Item(ModelExample(name: 'ABC 123', age: 3), true),
        Item(ModelExample(name: 'ACB 132', age: 13), false),
        Item(ModelExample(name: 'BAC 213', age: 23), false),
        Item(ModelExample(name: 'BCA 231', age: 33), false),
        Item(ModelExample(name: 'CAB 312', age: 43), false),
        Item(ModelExample(name: 'CBA 321', age: 53), false),
      ];

      //2ª Update controller with new listToFill
      controllerStartWithValue.updateValues(listToFill);
    },
    child: Text('Changing list'),
  ),
),
Important About Models
For the search to work in an offline list, we need to implement the following items in your model or in your object's data class:

toString, equals and also hashcode

Here's how to do it
class ModelExample {
  final String name;
  final int age;

  ModelExample({this.name, this.age});

  @override
  String toString() {
    return '$name $age';
  }

  factory ModelExample.fromJson(Map<String, dynamic> json) {
    if (json == null) return null;
    return ModelExample(
      name: json["name"],
      age: json["age"],
    );
  }

  static List<ModelExample> fromJsonList(List list) {
    if (list == null) return null;
    return list.map((item) => ModelExample.fromJson(item)).toList();
  }
  
  //In this case I customized it so that the search returns everything that contains part of the name or age
  @override
  operator ==(object) => this.name.toLowerCase().contains(object.toLowerCase()) || this.age.toString().contains(object);
  
  @override
  int get hashCode => name.hashCode ^ age.hashCode;
}

Roadmap

This is our current roadmap. Please, feel free to request additions/changes.

Feature Progress
Offline List ✅
Http Request Support ✅
Widget Consume for ChangeNotifier ✅
Widget consume for NotifierValue ✅
Just one selected item ✅
Multiple item selection ✅
Search after last input ✅
Cancel to keep old items ✅
Remove items by touch ✅
Nice layout default ✅
Custom layout support ✅
Progress on search request ✅
Custom selected animation ✅
Custom animated action buttons ✅
Custom message when no data found ✅
Custom theme colors ✅
Many other customizations ✅
Documentation - in progress 💔

Features and bugs

Please send feature requests and bugs at the issue tracker.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。