From 4b33f98a0120aeaa00abf2f095fcd2cc080906c0 Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Mon, 17 Nov 2025 23:14:49 +0100 Subject: [PATCH] Add DropdownMenuFormField.decorationBuilder (#178640) ## Description This PR adds `DropdownMenuFormField.decorationBuilder` and passes it to the underlying `DropdownMenu`. ## Related Issue Follow-up to https://github.com/flutter/flutter/pull/176264 which added `DropdownMenu.decorationBuilder`. ## Tests - Adds 1 test. --- .../material/dropdown_menu_form_field.dart | 2 ++ .../dropdown_menu_form_field_test.dart | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/packages/flutter/lib/src/material/dropdown_menu_form_field.dart b/packages/flutter/lib/src/material/dropdown_menu_form_field.dart index 405e0f89c16..40c23fc2d08 100644 --- a/packages/flutter/lib/src/material/dropdown_menu_form_field.dart +++ b/packages/flutter/lib/src/material/dropdown_menu_form_field.dart @@ -50,6 +50,7 @@ class DropdownMenuFormField extends FormField { TextAlign textAlign = TextAlign.start, // TODO(bleroux): Clean this up once `InputDecorationTheme` is fully normalized. Object? inputDecorationTheme, + DropdownMenuDecorationBuilder? decorationBuilder, MenuStyle? menuStyle, this.controller, T? initialSelection, @@ -95,6 +96,7 @@ class DropdownMenuFormField extends FormField { textStyle: textStyle, textAlign: textAlign, inputDecorationTheme: inputDecorationTheme, + decorationBuilder: decorationBuilder, menuStyle: menuStyle, controller: state.textFieldController, initialSelection: state.value, diff --git a/packages/flutter/test/material/dropdown_menu_form_field_test.dart b/packages/flutter/test/material/dropdown_menu_form_field_test.dart index 4f884b504e3..3b5ea0ed49c 100644 --- a/packages/flutter/test/material/dropdown_menu_form_field_test.dart +++ b/packages/flutter/test/material/dropdown_menu_form_field_test.dart @@ -472,6 +472,36 @@ void main() { expect(dropdownMenu.inputDecorationTheme, inputDecorationTheme); }); + testWidgets('Passes decorationBuilder to underlying DropdownMenu', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold(body: DropdownMenuFormField(dropdownMenuEntries: menuEntries)), + ), + ); + + // Check default value. + DropdownMenu dropdownMenu = tester.widget(find.byType(DropdownMenu)); + expect(dropdownMenu.decorationBuilder, null); + + InputDecoration buildDecoration(BuildContext context, MenuController controller) { + return const InputDecoration(labelText: 'labelText'); + } + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: DropdownMenuFormField( + decorationBuilder: buildDecoration, + dropdownMenuEntries: menuEntries, + ), + ), + ), + ); + + dropdownMenu = tester.widget(find.byType(DropdownMenu)); + expect(dropdownMenu.decorationBuilder, buildDecoration); + }); + testWidgets('Passes menuStyle to underlying DropdownMenu', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp(