Allow null DropdownButton values#6971
Conversation
| children: config.items | ||
| // The button's size is defined by its largest menu item. If value is | ||
| // null then an item does not appear. | ||
| new Opacity( |
There was a problem hiding this comment.
Why use an opacity here? I guess that works, but I would have expected there to be a more direct way of making a subtree take up space but be invisible.
In particular, the children can still be hit with opacity 0.0, but presumably that's not what you want.
| new Opacity( | ||
| opacity: _selectedIndex == null ? 0.0 : 1.0, | ||
| child: new IndexedStack( | ||
| index: _selectedIndex ?? 0, |
There was a problem hiding this comment.
Maybe you should teach indexedstack to take a null index, which means "show none of the children"
There was a problem hiding this comment.
Sure, sounds good, I'll do that.
| @@ -411,28 +412,31 @@ class DropdownButtonHideUnderline extends InheritedWidget { | |||
| class DropdownButton<T> extends StatefulWidget { | |||
There was a problem hiding this comment.
at some point we should document T here and in the related classes (not necessarily in this PR unless you're feeling particularly heroic)
There was a problem hiding this comment.
I will put it on my TODO list.
Specifying null as the DropdownButton's value causes the dropdown to appear empty until a selection is made.
If the dropdown is added to an InputContainer, a hint and label can be displayed as well.
Changed IndexedStack: specifying index: null prevents the widget from displaying anything or responding to input.
Fixes #6422
Here's an example that demos this feature along with InputContainer.