selectedItemBuilder property

DropdownButtonBuilder? selectedItemBuilder
final

A builder to customize the dropdown buttons corresponding to the CustomDropdownMenuItems in items.

When a CustomDropdownMenuItem is selected, the widget that will be displayed from the list corresponds to the CustomDropdownMenuItem of the same index in items.

{@tool dartpad --template=stateful_widget_scaffold}

This sample shows a CustomDropdownButton with a button with Text that corresponds to but is unique from CustomDropdownMenuItem.

final List<String> items = <String>['1','2','3'];
String selectedItem = '1';

@override
Widget build(BuildContext context) {
  return Padding(
    padding: const EdgeInsets.symmetric(horizontal: 12.0),
    child: CustomDropdownButton<String>(
      value: selectedItem,
      onChanged: (String string) => setState(() => selectedItem = string),
      selectedItemBuilder: (BuildContext context) {
        return items.map<Widget>((String item) {
          return Text(item);
        }).toList();
      },
      items: items.map((String item) {
        return CustomDropdownMenuItem<String>(
          child: Text('Log $item'),
          value: item,
        );
      }).toList(),
    ),
  );
}

{@end-tool}

If this callback is null, the CustomDropdownMenuItem from items that matches value will be displayed.

Implementation

final DropdownButtonBuilder? selectedItemBuilder;