我在我的应用程序中有一个小部件,我想要在可发酵类中搜索它们的名称。名称呈现正常,搜索工作良好,但是当我单击它们时,控制器未更新,如果我在vscode上保存应用程序,则会更新。
我使用Dropdown2包,我发现它更容易实现,并且找到了示例代码可以正常工作。
这是我的代码。
我使用Dropdown2包,我发现它更容易实现,并且找到了示例代码可以正常工作。
这是我的代码。
DropdownButtonHideUnderline(
child: DropdownButton2(
isExpanded: true,
hint: Text(
'Selecione um fermentável',
style: textTheme.bodyMedium,
),
items: fermentables
.map((item) => DropdownMenuItem<String>(
value: item.name.toLowerCase(),
child: Text(
item.name,
style: const TextStyle(
fontSize: 14,
),
),
))
.toList(),
value: selectedFermentable,
onChanged: (value) {
setState(() {
selectedFermentable = value as String;
});
},
buttonHeight: 40,
buttonWidth: 200,
itemHeight: 40,
dropdownMaxHeight: 400,
searchController: fermentableName,
searchInnerWidgetHeight: 50,
searchInnerWidget: Container(
height: 50,
padding: const EdgeInsets.only(
top: 8,
bottom: 4,
right: 8,
left: 8,
),
child: TextFormField(
expands: true,
maxLines: null,
controller: fermentableName,
decoration: InputDecoration(
isDense: true,
contentPadding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 8,
),
hintText: 'Pesquise um fermentável',
hintStyle: textTheme.bodyMedium,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
),
searchMatchFn: (item, searchValue) {
return (item.value
.toString()
.toLowerCase()
.contains(searchValue));
},
onMenuStateChange: (isOpen) {
if (!isOpen) {
fermentableName.clear();
}
},
),
),