Fix DropdownButton bug (#65915)
This commit is contained in:
@@ -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();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user