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

Allow handling the handleTap event from a GlobalKey #304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MarvinQuevedo
Copy link

We need to show the dropdown from a external widget equal to old versions

@AhmedLSayed9
Copy link
Owner

This is already applicable.

Starting from version 3.0.0-beta.13, instead of:

final dropdownKey = GlobalKey<DropdownButton2State>();

@override
Widget build(BuildContext context) {
  return Column(
    children:[
      DropdownButton2<String>(
        // Other properties...
        key: dropdownKey,
      );
      // Open the dropdown programmatically, like when another button is pressed:
      ElevatedButton(
        onTap: () => dropdownKey.currentState!.callTap(),
      ),
    ],
  );
}

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(),
      ),
    ],
  );
}

@AhmedLSayed9 AhmedLSayed9 added the question Further information is requested label Jul 9, 2024
@MarvinQuevedo
Copy link
Author

Hi, If I am not wrong, you can see here that the state class is private, on my PR I make It to public removing the underscore and make public the handleTab method too, the two are private on your current code,,

https://github.com/AhmedLSayed9/dropdown_button2/blob/master/packages/dropdown_button2/lib/src/dropdown_button2.dart#L396

@AhmedLSayed9
Copy link
Owner

Hi, If I am not wrong, you can see here that the state class is private, on my PR I make It to public removing the underscore and make public the handleTab method too, the two are private on your current code,,

https://github.com/AhmedLSayed9/dropdown_button2/blob/master/packages/dropdown_button2/lib/src/dropdown_button2.dart#L396

Yes, that's on purpose.

You don't need to call the callTap method anymore. just 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(),
      ),
    ],
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants