Unverified Commit 7eeab266 authored by xubaolin's avatar xubaolin Committed by GitHub

Fix DropdownButton bug (#65915)

parent 66cf8d47
...@@ -1303,16 +1303,12 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi ...@@ -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 // The width of the button and the menu are defined by the widest
// item and the width of the hint. // item and the width of the hint.
List<Widget> items; // We should explicitly type the items list to be a list of <Widget>,
if (_enabled) { // otherwise, no explicit type adding items maybe trigger a crash/failure
items = widget.selectedItemBuilder == null // when hint and selectedItemBuilder are provided.
? List<Widget>.from(widget.items!) final List<Widget> items = widget.selectedItemBuilder == null
: widget.selectedItemBuilder!(context); ? (_enabled ? List<Widget>.from(widget.items!) : <Widget>[])
} else { : List<Widget>.from(widget.selectedItemBuilder!(context));
items = widget.selectedItemBuilder == null
? <Widget>[]
: widget.selectedItemBuilder!(context);
}
int? hintIndex; int? hintIndex;
if (widget.hint != null || (!_enabled && widget.disabledHint != null)) { if (widget.hint != null || (!_enabled && widget.disabledHint != null)) {
......
...@@ -1945,7 +1945,7 @@ void main() { ...@@ -1945,7 +1945,7 @@ void main() {
}); });
}, },
selectedItemBuilder: (BuildContext context) { selectedItemBuilder: (BuildContext context) {
return items.map<Widget>((String item) { return items.map((String item) {
return Text('You have selected: $item'); return Text('You have selected: $item');
}).toList(); }).toList();
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment