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
// 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)) {
......
......@@ -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();
},
......
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