I need more flexibility in presenting/dismissing a DropdownButton's list of choices in flutter. I want to be able to show/hide DropdownButton as a result of some other user action than clicking on it. It doesn't seem these methods are exposed in the doc. What is a good way to do this?
Asked
Active
Viewed 1,385 times
4
-
Are you talking about the whole widget or the icon? – creativecreatorormaybenot Sep 16 '18 at 21:20
-
The whole widget. – Flying_Banana Sep 16 '18 at 21:20
-
You could change the widget key and rebuild to hide it when it is opened, but that is not a great solution and does not work the other way round. – creativecreatorormaybenot Sep 16 '18 at 21:36
-
@creativecreatorormaybenot that does indeed sound more like a hack. – Flying_Banana Sep 16 '18 at 21:55
-
I don't think there is a direct option for doing that.You can create a variable to control the state eg `child:(visible)?DropDownButton():Container()` and control the `visible` variable with `setState()`. when visibility is not needed, the empty container will be used. check out more options here https://stackoverflow.com/questions/44489804/show-hide-widgets-on-flutter-programmatically – nonybrighto Sep 17 '18 at 04:37
-
That is not the state for whether the dropdown list is showing or not, but rather it is the visibility of the entire dropdown button, which is not what I need. – Flying_Banana Sep 17 '18 at 12:26
1 Answers
1
There is a specific widget for this:
Visibility( visible: false, child: Container(color: Colors.blue, width: 100, height: 100), ),
Use visible to show or hide the widget, i.e isVisible().
Put whatever as a child, as example Column or Row.

Ahmed Hammad
- 622
- 8
- 17