AhmedLSayed9 / dropdown_button2

Flutter's core Dropdown Button widget with steady dropdown menu and many other features.
https://pub.dev/packages/dropdown_button2
MIT License
271 stars 124 forks source link

Close programatically on Escape pressed #263

Closed busslina closed 5 months ago

busslina commented 6 months ago

Is it possible? I don't see any option like a controller or similar.

Thank you

AhmedLSayed9 commented 6 months ago

You can use Navigator.pop

busslina commented 5 months ago

You can use Navigator.pop

And what about if I want to open it programmatically too?

Seems to be needed a logic/controller to provide common operations on it that hides implementation like NavigatorPop.

AhmedLSayed9 commented 5 months ago

And what about if I want to open it programmatically too?

You can do:

final openDropdownListenable = ValueNotifier<Object?>(null);

@override
Widget build(BuildContext context) {
  return Column(
    children:[
      DropdownButton2<String>(
        // Other properties...
        openDropdownListenable: openDropdownListenable,
      );
      // Open the dropdown programmatically, like when another button is pressed:
      ElevatedButton(
        onTap: () => openDropdownListenable.value = Object(),
      ),
    ],
  );
}
busslina commented 5 months ago

@AhmedLSayed9 thanks!