Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open drop down button programatically #723

Closed
bdlukaa opened this issue Feb 5, 2023 · 2 comments · Fixed by #724
Closed

Open drop down button programatically #723

bdlukaa opened this issue Feb 5, 2023 · 2 comments · Fixed by #724
Labels
enhancement New feature or request

Comments

@bdlukaa
Copy link
Owner

bdlukaa commented Feb 5, 2023

Is your feature request related to a problem? Please describe.
Currently, there is no way to open a dropdown button programatically.

Describe the solution you'd like
Exposing DropDownButtonState, and use a key to open it

final dropdownKey = GlobalKey<DropDownButtonState>();

DropDownButton(
  key: dropdownKey,
  ...
);

to open the flyout:

dropdownKey.open();
dropdownKey.isOpen;
dropdownKey.close()

Describe alternatives you've considered
n/a

Additional context
#718

@bdlukaa bdlukaa added the enhancement New feature or request label Feb 5, 2023
@bdlukaa bdlukaa mentioned this issue Feb 6, 2023
3 tasks
@tonka3000
Copy link

tonka3000 commented Mar 5, 2023

@bdlukaa Thanks for the PR. Works great. The only thing I am missing is the referenced close method from your example above. Do I miss something?

I'm using 4.4.0

This is my example:

final dropdownKey = GlobalKey<DropDownButtonState>();

// ....
ShowActionsMenuIntent:
      CallbackAction<ShowActionsMenuIntent>(onInvoke: (intent) {
    if (dropdownKey.currentState != null) {
      var isOpen = dropdownKey.currentState?.isOpen ?? false;
      if (!isOpen) {
        dropdownKey.currentState!.open();
      }
      else {
         dropdownKey.currentState!.close(); // <= no close available
       }
    }
  }),

@bdlukaa
Copy link
Owner Author

bdlukaa commented Mar 7, 2023

@tonka3000 sorry, it was a mistake by my part. There is no .close() to close the flyout. To close it, use Navigator.of(context).pop() or, if you provide a navigator key, use navigatroKey.pop()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants