dropdown_button2
dropdown_button2 copied to clipboard
Does DropdownButton2 support keyboard for desktop apps
I am making a dektop app. Does DropdownButton2 support keyboard selection? In the standard DropdownButton I can expand the menu by pressing the enter button and then use keyboard up and down to go to the item and to select press enter again. I tried your example code I could not do that.
Can you try the latest beta version?
tried with the latest beta keyboard input is working thanks. any eta when it will be out of beta? thanks
I'm still thinking if we can add pagination or not. It shouldn't take much time if we don't include pagination in the next release :)
tried with the latest beta keyboard input is working thanks. any eta when it will be out of beta? thanks
I have the same problem but I can't solve it with the beta, could you give me an example of the implementation you did :) in this moment need use DropdownButtonFormField2
I could solve it in the following way, I can that the DropdownButtonFormField2 does not allow me to select an element with the keyboard until it has not been previously selected, so I had to create an extension of DropdownItem that has the property focusNode which serves me to assign the focus programmatically to any element of the DropdownButtonFormField2. In my case I indicate that if there are no previously selected elements it assigns the focus to the first element of the list otherwise it maintains the focus to the element that at the moment has it.
CustomDropdownItem:
class CustomDropdownItem<T> extends DropdownItem<T> {
final FocusNode focusNode;
const CustomDropdownItem({
super.key,
required super.value,
required super.child,
required this.focusNode,
});
@override
Widget build(BuildContext context) {
return Focus(
focusNode: focusNode,
child: child,
);
}
}
Building the DropdownButtonFormField2 with the function onMenuStateChange:
onMenuStateChange: (isOpen) {
if (isOpen) {
final CustomDropdownItem<T>? newVal =
selectedItem ?? (widget.items.isNotEmpty ? widget.items.first : null);
if (newVal != null) {
Future.delayed(const Duration(milliseconds: 100), () {
if (widget.items.length > 1) {
if (newVal.focusNode.hasPrimaryFocus || newVal.focusNode.canRequestFocus) {
FocusScope.of(context).requestFocus(newVal.focusNode);
}
}
});
}
}
},
Result:
Closing in favor of #339