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

Dropdownbutton does not pop up on tap #54951

Closed
maheshj01 opened this issue Apr 16, 2020 · 7 comments
Closed

Dropdownbutton does not pop up on tap #54951

maheshj01 opened this issue Apr 16, 2020 · 7 comments

Comments

@maheshj01
Copy link
Member

maheshj01 commented Apr 16, 2020

I have a dropdown widget I understand that we have to call setState to change the value of the dropdown widget but the thing is dropdown isnt popping up in the first place in the UI until someother widget does the setState in the same Widget.

I have a counter widget just like the flutter counter app and in the same widget I also have a dropdown widget ,The dropdown widget doesnt pop up, on tap but when I hit the counter widget( which calls the setstate to change the counter value ),After that the dropdown widget is available to access.seems like the dropdown is disabled until the first setstate in the widget
I have other dropdowns in the app it seems to work well but I am scratching my head since few hours to find out whats the issue

here is my dropdown widget

 String currentSelectedValue = null;
Widget dropDownWidget(List<String> reasons) {
    return Container(
      padding: HALIGN_16_VALIGN_15,
      width: size.width / 1.2,
      decoration: BoxDecoration(
          border: Border.all(
        width: 0.5,
        color: enabledcolor,
      )),
      child: DropdownButtonHideUnderline(
          child: DropdownButton<String>(
        hint: Text(
          'Select Reason to Report',
          style: TextStyle(fontSize: 12),
        ),
        value: currentSelectedValue,
        isDense: true,
        isExpanded: true,
        onChanged: (newValue) {
          print(newValue);
          setState(() {
            currentSelectedValue = newValue;
            widget.onReasonSelected(currentSelectedValue);
          });
        },
        icon: Icon(Icons.keyboard_arrow_down),
        items: reasons.map((String value) {
          return DropdownMenuItem<String>(
            value: value,
            child: Text(
              value,
              style: TextStyle(fontSize: 14),
            ),
          );
        }).toList(),
      )),
    );
  }

quantity widget // ontap calls setState which allows interaction with the dropdown

 Widget _quantityWidget() {
    return Container(
      // margin: const EdgeInsets.symmetric(horizontal: 22, vertical: 5),
      child: Row(
        children: <Widget>[
          const Text(
            'QTY ',
            style: BOLD_STYLE,
          ),
          GestureDetector(
            onTap: () {
              print('count=$reportProductCount');
              if (reportProductCount > 0) {
                int qty = reportProductCount--;
                setState(() {});
                widget.onCountChange(qty);
              }
            },
            child: Container(
                height: 24,
                width: 40,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(2.0),
                    shape: BoxShape.rectangle,
                    border: Border.all(color: marginColor)),
                child: Center(
                    child: Icon(
                  Icons.remove,
                  size: 16,
                ))),
          ),
          Container(
            margin: HORIZONTAL_ALIGN_10,
            child: Text('$reportProductCount',
                style:
                    const TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
          ),
          GestureDetector(
            onTap: () {
              print('count=$reportProductCount');
              if (reportProductCount < int.parse(widget.quantity)) {
                int qty = ++reportProductCount;
                setState(() {});
                widget.onCountChange(qty);
              } else {
                utility.showError(
                    'you cannot report more than available quantity');
              }
            },
            child: Container(
                height: 24,
                width: 40,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(2.0),
                    shape: BoxShape.rectangle,
                    border: Border.all(color: marginColor)),
                child: Center(
                    child: Icon(
                  Icons.add,
                  size: 16,
                ))),
          ),
        ],
      ),
    );
  }

heres my flutter doctor output

[✓] Flutter (Channel master, v1.18.0-5.0.pre.57, on Mac OS X 10.15.4 19E266, locale en-GB)
    • Flutter version 1.18.0-5.0.pre.57 at /Users/mac006/Documents/flutter
    • Framework revision a5765331bc (7 days ago), 2020-04-09 16:15:01 -0700
    • Engine revision 5b4b1f33c6
    • Dart version 2.8.0 (build 2.8.0-dev.20.0 dcdc71d763)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/mac006/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3.1, Build version 11C504
    • CocoaPods version 1.9.1

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 44.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.44.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.9.1

[✓] Connected device (1 available)
    • iPhone 11 Pro Max • 239ACB82-12EF-47BB-9285-B3597C525ACA • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

• No issues found!

if you see in the above gif the dropdown gets enabled as soon as setstate is called by the counter widget .

the image before the counter widget calls to setstate

Screenshot 2020-04-16 at 5 48 19 PM

please let me know if you need some more info to figure out the issue.

@maheshj01 maheshj01 changed the title dropdownbutton onchange not triggering Dropdownbutton onchange not triggering until setState is called Apr 16, 2020
@VladyslavBondarenko
Copy link

@maheshmnj
It's not an issue,
You are expected to change a value in the setState

onChanged: (String value) {
            setState(() {
              _value = value;
            });
          }

@maheshj01 maheshj01 changed the title Dropdownbutton onchange not triggering until setState is called Dropdownbutton does not pop up on tap Apr 16, 2020
@maheshj01
Copy link
Member Author

@maheshmnj
It's not an issue,
You are expected to change a value in the setState

onChanged: (String value) {
            setState(() {
              _value = value;
            });
          }

@VladyslavBondarenko thank you very much for the prompt reply,I was actually editing the post and accidently submitted, that caused a little confusion,I have updated the issue with little detail can you please check it and reopen the issue

@VladyslavBondarenko
Copy link

@maheshmnj
could you provide a minimal complete code sample to reproduce your case?

@VladyslavBondarenko VladyslavBondarenko added in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Apr 16, 2020
@maheshj01
Copy link
Member Author

@maheshmnj
could you provide a minimal complete code sample to reproduce your case?

sure I will do that

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 16, 2020
@maheshj01
Copy link
Member Author

maheshj01 commented Apr 16, 2020

@VladyslavBondarenko I was able to reproduce the issue with a minimal code can you please check this out https://github.com/maheshmnj/flutter-dropdown-issue-54951 this is the exact code that I have in my project heres the output

@maheshj01
Copy link
Member Author

maheshj01 commented Apr 17, 2020

@VladyslavBondarenko I found the issue,I am actually loading the list data from the network and while the data is being loaded the dropdown has an empty list and The dropdown remains in empty state and probably when it has empty list it remains disabled and once the list is available with the data from network to render it inside the dropdown we have to call setState (This was missing in my code,need to call setState as soon as list has the data from network) so you can mark this issue as resolved and close the issue

@lock
Copy link

lock bot commented May 6, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock bot locked and limited conversation to collaborators May 6, 2020
@maheshj01 maheshj01 removed the in triage Presently being triaged by the triage team label Jul 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants