Skip to content

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