之前的数据是
// 列表视图(`ListView`)中要显示的数据。
List<GoodsListsParentData> _collectionListData = <GoodsListsParentData>[];
根据TextFiled的改变来动态过滤数据
添加了
//当前所有列表数据
List<GoodsListsParentData> _currentAllData = <GoodsListsParentData>[];
//搜索后过滤的数据
List<GoodsListsParentData> _searchCollectionListData =
<GoodsListsParentData>[];
当数据变化的时候两个跟随变化
inputCallBack: (value) {
setState(() {
_search = value;
if (_currentAllData.isEmpty) {
_currentAllData.addAll(_collectionListData);
}
_searchCollectionListData = _currentAllData
.where((element) => (element.bdyContent.contains(_search) ||
element.name.contains(_search)))
.toList();
if (_search.isEmpty) {
if (_currentAllData.isNotEmpty) {
_collectionListData.clear();
_collectionListData.addAll(_currentAllData);
}
} else {
_collectionListData.clear();
_collectionListData.addAll(_searchCollectionListData);
}
});