https://pub.dev/packages/searchable_dropdown#Single-menu
List<DropdownMenuItem> _serviceItems = [];
String selectedServiceVal;
void initState() {
super.initState();
...
setState(() {
_serviceItems = [];
_serviceItems.add(DropdownMenuItem(
key: Key("1"),
child: Text("test"),
value: "test",
));
_serviceItems.add(DropdownMenuItem(
key: Key("2"),
child: Text("test1 - A"),
value: "test1",
));
_serviceItems.add(DropdownMenuItem(
key: Key("3"),
child: Text("test1 - B"),
value: "test1",
));
_serviceItems.add(DropdownMenuItem(
key: Key("4"),
child: Text("test3"),
value: "test3",
));
});
...
}
Widget bodyTemp() {
return SearchableDropdown.single(
items: _customerItems,
value: selectedCustomerVal,
hint: "hint message.",
searchHint: null,
onChanged: (value) async {
print(value);
if (value == "") {
await _asyncInputDialog(context);
value = _newCustomer;
}
setState(() {
selectedCustomerVal = value;
_subjectTextController.text =
'${selectedServiceVal ?? ''} - ${selectedCustomerVal ?? ''}';
});
},
dialogBox: false,
isExpanded: true,
menuConstraints: BoxConstraints.tight(Size.fromHeight(350)),
);
}
value를 통해 검색가능함
(그래서 보여지는 child 또한 value와 동일하게 가야됨)
widget그릴 때 value속성으로 찾기 때문에 value가 동일 할 경우
무조건 순서 상 위에있는 요소가 선택되었다고 나옴.
SearchableDropdown.single(
key: Key(selectedServiceKey),
items: _serviceItems,
value: selectedServiceVal,
...
onChanged: (value) async {
print(value);
if (value == "") {
await _asyncInputDialog(context);
value = _newCustomer;
}
setState(() {
selectedServiceKey = key;
selectedServiceVal = value;
_subjectTextController.text =
'${selectedServiceVal ?? ''} - ${selectedServiceVal ?? ''}';
});
},
...
);
selectedServiceKey = key;
가 안됨.
onChange: (val){}
밖에 없음... 2번째 인자로 보내주는 요소 없음