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

Does this widget allow you to open the button programmatically? #33

Closed
RichardJECooke opened this issue May 19, 2022 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@RichardJECooke
Copy link

If so, how please?

@AhmedLSayed9
Copy link
Owner

AhmedLSayed9 commented May 20, 2022

Upgrade to latest version. Here's an example of how to do it:

  final dropdownKey = GlobalKey<DropdownButton2State>();
  final List<String> items = [
    'Item1',
    'Item2',
    'Item3',
    'Item4',
  ];
  String? selectedValue;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            GestureDetector(
              onTap: () {
                dropdownKey.currentState!.callTap();
              },
              child: Container(
                height: 100,
                width: 100,
                color: Colors.red,
              ),
            ),
            DropdownButtonHideUnderline(
              child: DropdownButton2(
                key: dropdownKey,
                hint: Text(
                  'Select Item',
                  style: TextStyle(
                    fontSize: 14,
                    color: Theme.of(context).hintColor,
                  ),
                ),
                items: items
                    .map((item) => DropdownMenuItem<String>(
                          value: item,
                          child: Text(
                            item,
                            style: const TextStyle(
                              fontSize: 14,
                            ),
                          ),
                        ))
                    .toList(),
                value: selectedValue,
                onChanged: (value) {
                  setState(() {
                    selectedValue = value as String;
                  });
                },
                buttonHeight: 40,
                buttonWidth: 140,
                itemHeight: 40,
              ),
            ),
          ],
        ),
      ),
    );
  }

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

No branches or pull requests

2 participants