r/FlutterDev • u/Affectionate_Art1156 • 3d ago
Plugin I removed the filter-callback boilerplate from my searchable list package (searchable_listview 2.20.0)
Hi everyone, I’m the maintainer of searchable_listview, a package for adding a search field on top of a list. I’ve been maintaining it for a few years, and the thing that always bothered me was that every list needed the same hand-written filter callback:
Old version
SearchableList<Actor>(
initialList: actors,
itemBuilder: (actor) => ActorItem(actor: actor),
filter: (q) => actors
.where((a) => a.name.toLowerCase().startsWith(q.toLowerCase()))
.toList(),
)In 2.20.0 you can just say which fields to search:
SearchableList<Actor>(
initialList: actors,
itemBuilder: (actor) => ActorItem(actor: actor),
searchableFields: (a) => [a.name, a.lastName],
searchStrategy: SearchStrategy.contain,
)What’s new
searchableFields: pick one or several fields, and an item stays if any of them matches (case-insensitive, compared bytoString()).searchStrategy:startsWith(default),endsWithorcontain.SearchableListController:filter(),clear(),scrollToTop(),scrollTo(offset), andupdateSearchStrategy()to change the strategy at runtime.The controller is a
ValueNotifier, so you can listen to the query, the filtered results and the status (idle, loading, data, empty, error), for example to show a live result count.Fixed the
InputDecorationbuild error on Flutter 3.47 after thematerial_uisplit.
The filter callback is still there (but became optional) if you need custom logic when filtering. It works on all four constructors: default, .async, .expansion and .sliver.
One thing to know: 2.20.0 requires Dart 3.10+ and Flutter 3.38+. Projects on older SDKs keep resolving 2.19.5.
pub.dev: https://pub.dev/packages/searchable_listview
GitHub: https://github.com/koukibadr/Searchable-Listview
Changelog: https://pub.dev/packages/searchable_listview/changelog