我正在使用 dropdown_search 版本 0.4.3 包,我可以在单击搜索栏时使用项目填充下拉列表,但是当我开始输入时它不会返回任何项目。我正在从 Firebase 云存储中获取初始数据。请在下面查看我的代码。
@override
Widget _buildBody() {
return OurContainer(
child: Column(
children: <Widget>[
DropdownSearch(
showSearchBox: true,
isFilteredOnline: true,
onFind: (String filter) => getData(filter),
popupItemBuilder: _customPopupItemBuilderExample,
dropdownBuilder: _customDropDownExample,
),
],
),
);
}
Widget _customDropDownExample(
BuildContext context, MainCategoryModel item, String itemDesignation) {
return Container(
child: (item?.name == null)
? ListTile(
contentPadding: EdgeInsets.all(0),
title: Text("No item selected"),
)
: ListTile(
contentPadding: EdgeInsets.all(0),
title: Text(item.name),
),
);
}
Widget _customPopupItemBuilderExample(
BuildContext context, MainCategoryModel item, bool isSelected) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 8),
decoration: !isSelected
? null
: BoxDecoration(
border: Border.all(color: Theme.of(context).primaryColor),
borderRadius: BorderRadius.circular(5),
color: Colors.white,
),
child: ListTile(
selected: isSelected,
title: Text(item.name),
subtitle: Text(item.name.toString()),
),
);
}
Future<List<MainCategoryModel>> getData(filter) async {
final tempList = <MainCategoryModel>[];
if (filter.length > 0) {
tempList.addAll(_mainCategoryList
.where((element) => element.name.toLowerCase().contains(filter)));
_mainCategoryList.addAll(tempList);
} else {
_mainCategoryList.clear();
_mainCategoryList.addAll(await OurDatabase().getMainCategory());
}
return _mainCategoryList;
}