Skip to content

Commit 951f2f7

Browse files
authored
[material_ui] Add scrollPadding property to DropdownMenuFormField (flutter#12735)
Port of flutter#184059 to flutter/packages, per the instructions in flutter#188444. This change adds the `scrollPadding` property to `DropdownMenuFormField` and forwards it to the underlying `DropdownMenu`, bringing the form field variant into parity with `DropdownMenu`. ## Related Issues The original issue has been closed, but the following comment explains the remaining gap that this PR addresses: flutter#182890 (comment) > The merged PR [flutter#183109](flutter#183109) covers `DropdownMenu`, but `DropdownMenuFormField` still doesn't expose `scrollPadding`. I'm opening a follow-up PR to address that remaining gap. [flutter#184059](flutter#184059) ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.
1 parent 10cde9a commit 951f2f7

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎packages/material_ui/lib/src/dropdown_menu_form_field.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class DropdownMenuFormField<T> extends FormField<T> {
4949
bool enableFilter = false,
5050
bool enableSearch = true,
5151
TextInputType? keyboardType,
52+
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
5253
TextStyle? textStyle,
5354
TextAlign textAlign = TextAlign.start,
5455
// TODO(bleroux): Clean this up once `InputDecorationTheme` is fully normalized.
@@ -120,6 +121,7 @@ class DropdownMenuFormField<T> extends FormField<T> {
120121
enableFilter: enableFilter,
121122
enableSearch: enableSearch,
122123
keyboardType: keyboardType,
124+
scrollPadding: scrollPadding,
123125
textStyle: textStyle,
124126
textAlign: textAlign,
125127
inputDecorationTheme: inputDecorationTheme,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Adds the `scrollPadding` property to `DropdownMenuFormField`, forwarding it to the underlying `DropdownMenu`.
3+
version: minor

‎packages/material_ui/test/dropdown_menu_form_field_test.dart‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,33 @@ void main() {
421421
expect(dropdownMenu.enableSearch, enableSearch);
422422
});
423423

424+
testWidgets('Passes scrollPadding to underlying DropdownMenu', (WidgetTester tester) async {
425+
await tester.pumpWidget(
426+
MaterialApp(
427+
home: Scaffold(body: DropdownMenuFormField<MenuItem>(dropdownMenuEntries: menuEntries)),
428+
),
429+
);
430+
431+
// Check default value.
432+
DropdownMenu<MenuItem> dropdownMenu = tester.widget(find.byType(DropdownMenu<MenuItem>));
433+
expect(dropdownMenu.scrollPadding, const EdgeInsets.all(20.0));
434+
435+
const EdgeInsets scrollPadding = EdgeInsets.zero;
436+
await tester.pumpWidget(
437+
MaterialApp(
438+
home: Scaffold(
439+
body: DropdownMenuFormField<MenuItem>(
440+
scrollPadding: scrollPadding,
441+
dropdownMenuEntries: menuEntries,
442+
),
443+
),
444+
),
445+
);
446+
447+
dropdownMenu = tester.widget(find.byType(DropdownMenu<MenuItem>));
448+
expect(dropdownMenu.scrollPadding, scrollPadding);
449+
});
450+
424451
testWidgets('Passes keyboardType to underlying DropdownMenu', (WidgetTester tester) async {
425452
await tester.pumpWidget(
426453
MaterialApp(

0 commit comments

Comments
 (0)