Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/material_ui/lib/src/dropdown_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ class DropdownMenu<T> extends StatefulWidget {

/// The builder function used to create the [InputDecoration] passed to the text field.
///
/// If the resulting [InputDecoration.prefixIcon] is null, [leadingIcon] is
/// assigned as the prefix icon.
///
/// If a value is provided for this property and the resulting [InputDecoration.suffixIcon]
/// is null, a default [IconButton] is assigned as the suffix icon. This button's icon will
/// use [trailingIcon] and [selectedTrailingIcon] if those are explicitly defined; otherwise,
Expand Down Expand Up @@ -1266,6 +1269,9 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
final DropdownMenuDecorationBuilder decorationBuilder =
widget.decorationBuilder ?? _buildDefaultDecoration;
InputDecoration decoration = decorationBuilder(context, controller);
if (widget.leadingIcon != null && decoration.prefixIcon == null) {
decoration = decoration.copyWith(prefixIcon: widget.leadingIcon);
}
// If no suffixIcon is provided, the default IconButton is used for convenience.
if (decoration.suffixIcon == null) {
decoration = decoration.copyWith(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changelog: |
- Fixes `DropdownMenuFormField.leadingIcon` not being shown in the text field.
version: patch
26 changes: 26 additions & 0 deletions packages/material_ui/test/dropdown_menu_form_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,32 @@ void main() {
expect(dropdownMenu.leadingIcon, leadingIcon);
});

testWidgets('leadingIcon is shown in the text field prefix decoration', (
WidgetTester tester,
) async {
const Widget leadingIcon = Icon(Icons.check);

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: DropdownMenuFormField<MenuItem>(
leadingIcon: leadingIcon,
dropdownMenuEntries: menuEntries,
),
),
),
);

final TextField textField = tester.widget(find.byType(TextField));
final Widget? prefixIcon = textField.decoration?.prefixIcon;
expect(prefixIcon, isNotNull);
final Finder prefixCheckIcon = find.descendant(
of: find.byWidget(prefixIcon!),
matching: find.byIcon(Icons.check),
);
expect(prefixCheckIcon, findsOneWidget);
});

testWidgets('Passes trailingIcon to underlying DropdownMenu', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
Expand Down