Fix DropdownButton bug (#65915)

This commit is contained in:
xubaolin
2020-10-14 16:52:03 +08:00
committed by GitHub
parent 66cf8d47a3
commit 7eeab2666b
2 changed files with 7 additions and 11 deletions

View File

@@ -1303,16 +1303,12 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
// The width of the button and the menu are defined by the widest
// item and the width of the hint.
List<Widget> items;
if (_enabled) {
items = widget.selectedItemBuilder == null
? List<Widget>.from(widget.items!)
: widget.selectedItemBuilder!(context);
} else {
items = widget.selectedItemBuilder == null
? <Widget>[]
: widget.selectedItemBuilder!(context);
}
// We should explicitly type the items list to be a list of <Widget>,
// otherwise, no explicit type adding items maybe trigger a crash/failure
// when hint and selectedItemBuilder are provided.
final List<Widget> items = widget.selectedItemBuilder == null
? (_enabled ? List<Widget>.from(widget.items!) : <Widget>[])
: List<Widget>.from(widget.selectedItemBuilder!(context));
int? hintIndex;
if (widget.hint != null || (!_enabled && widget.disabledHint != null)) {

View File

@@ -1945,7 +1945,7 @@ void main() {
});
},
selectedItemBuilder: (BuildContext context) {
return items.map<Widget>((String item) {
return items.map((String item) {
return Text('You have selected: $item');
}).toList();
},