advanced_search 包通过强大的文本字段增强了 Flutter 应用程序,用于搜索预定义的数据集。它支持可自定义的搜索逻辑、实时过滤以及基于用户输入的结果建议。该包设计高效且灵活,可在 Android、iOS、Web、macOS、Windows 和 Linux 等多个平台上无缝集成。适用于需要智能搜索功能且设置简单的应用程序,提供简洁的界面和可扩展的配置选项。
适合场景
实现可搜索的下拉菜单
构建动态产品或用户搜索界面
在表单中创建自动完成功能
启用大型数据集的快速筛选
支持多语言搜索查询
主要特点
实时搜索,即时结果
可配置的搜索算法
可自定义的搜索建议界面
跨平台兼容性
可扩展的结果筛选
支持不区分大小写和部分匹配
适合对象
开发搜索密集型应用的开发者
需要快速数据查找的应用程序
具有大型本地数据集的项目
需要智能建议的UI组件
希望获得低代码搜索解决方案的团队
使用建议
需要手动设置数据源
限于预定义的数据集
可能会影响非常大的数据集的性能
无内置后端集成
最适合本地或小规模数据处理
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
AdvancedSearch
Flutter library provides advanced capabilities for searching through a predefined list using TextField
How it works? Code talks better:
List<String> searchableList = ['Orange', 'Watermelon', 'Banana', ...etc];
AdvancedSearch( // This is basically an Input Text Field
data: searchableList,
maxElementsToDisplay: 7,
onItemTap: (index) {
// user just found what he needs, now it's your turn to handle that
},
onSearchClear: () {
// may be display the full list? or Nothing? it's your call
},
onSubmitted: (value, value2) {
// now you have a submitted search
},
onEditingProgress: (value, value2) {
// user is trying to lookup something, may be you want to help him?
},
)
The complete set of features this package gives you
Callbacks:
@required onItemTap // when user selects one of the displayed search results
onSearchClear // when user clears his search
onSubmitted // on submitting a search result
onEditingProgress // when the user is writing down his search words, want to give him live results? use this one
Required Inputs:
@required searchItems // your set of searchable data (give empty list if you don't want to provide one, then you can take the submitted search text and do whatever you want)
Options:
selectedTextColor // what is the text color that should reflects the matching text in search results
unSelectedTextColor // what is the text color that should reflects the unmatching text in search results
enabledBorderColor // Border color of TextField when it's enabled
disabledBorderColor // Border color of TextField when it's disabled
focusedBorderColor // Border color of TextField when it's on focus
cursorColor // Cursor Color, nothing more to tell
searchItemsWidget // Here you can pass a function that takes a String (will be replaced by search result item) and returns a Widget which will be used to list the search results instead of the default one [Don't forget to pass a reasonable singleItemHeight if you are passing this attribute]
maxElementsToDisplay (Default = 7) // as search results, what is the Maximum number you want to have
borderRadius (Default = 10.0) // radius for search results list border
fontSize (Default = 14.0) // for TextField and Search Results
singleItemHeight (Default = 45.0) // height for every single item in the search results list
verticalPadding (Default = 10.0) // Vertical Padding for the TextField
horizontalPadding (Default = 10.0) // Horizontal Padding for the TextField
itemsShownAtStart (Default = 10) // if the user didn't start sraching yet but clicked the search TextField, how many items should be displayed to him
hintText (Default = 'Enter a name') // hint text for search TextField
hintTextColor (Default = Colors.grey) // hint text color
autoCorrect (Default = false) // AutoCorrect functioanlity for TextField inputs
enabled (Default = true) // is the search should be enabled now, or not
bgColor (Default = Colors.white) // Background Color for Search Results widget
inputTextFieldBgColor // Background Color for the TextField itself
borderColor (Default = const Color(0xFFFAFAFA)) // Border Color for Search Results widget
searchMode (Default = SearchMode.CONTAINS) // what is the search criteria you want to Apply? should the results CONTAINS, STARTING_WITH, or EXACT_MATCH your search
caseSensitive (Default = false) // want your search to be applied on the searchable list as case sensitive, or not
minLettersForSearch (Default = 0) // what is the minimum letters that the user should type before starting to receive search results
clearSearchEnabled (Default = true) // should the user be able to clear his search, or not
showListOfResults (Default = true) // should a list of results be displayed to the user, or shall you just get what he searches for and you will do your things by your own
hideHintOnTextInputFocus (Default = false) // an option to hide the hin t text once the TextField get focused
autoListing (Default = false) // an option to display the results instandly without searching (in this case it shall display the max elements to be shown)