-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
It appears (to me) that DropdownMenuEntry.labelWidget is ignored when rendering the selected item.
What that means in practice is if I have a complex object (i.e. without a reasonable toString()), and I want to rely entirely on a provided itemBuilder, the label appears to take precedence over labelWidget.
For example, in the following custom wrapper widget, Branch is shown instead of itemBuilder(option):
final class DropdownSelect<T> extends StatelessWidget {
const DropdownSelect({
required this.options,
required this.itemBuilder,
required this.selected,
this.onSelect,
});
/// Options that can be selected.
final List<T> options;
/// Returns a [Widget] representing the item for [T].
///
/// ## Example
///
/// ```dart
/// TappableSelect(
/// itemBuilder: (item) => Text(item.name),
/// )
/// ```
final Widget Function(T) itemBuilder;
/// Currently selected element of type [T].
final T selected;
/// Invoked when an item is selected.
///
/// If `null` this select is read only.
final void Function(T)? onSelect;
@override
Widget build(BuildContext context) {
return DropdownMenu(
hintText: 'Select a branch',
dropdownMenuEntries: [
...options.map((option) {
return DropdownMenuEntry(
value: option,
label: '',
labelWidget: itemBuilder(option),
);
}),
],
enableFilter: true,
initialSelection: selected,
onSelected: invokeIfNonNull(onSelect),
label: Text('Branch'),
);
}
}Is that WAI?
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Type
Projects
Status
Done (PR merged)
