Skip to content

Commit eee1cff

Browse files
authored
Add DropdownMenu.restorationId (flutter#166684)
## Description This PR introduces `DropdownMenu.restorationId`. This value is passed to the inner `TextField.restorationId` which is required to activate the TextField restoration capability. ## Related Issue Required for flutter#163721 ## Tests Adds 1 test.
1 parent af2e733 commit eee1cff

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

packages/flutter/lib/src/material/dropdown_menu.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class DropdownMenu<T> extends StatefulWidget {
190190
this.closeBehavior = DropdownMenuCloseBehavior.all,
191191
this.maxLines = 1,
192192
this.textInputAction,
193+
this.restorationId,
193194
}) : assert(filterCallback == null || enableFilter);
194195

195196
/// Determine if the [DropdownMenu] is enabled.
@@ -527,6 +528,9 @@ class DropdownMenu<T> extends StatefulWidget {
527528
/// {@macro flutter.widgets.TextField.textInputAction}
528529
final TextInputAction? textInputAction;
529530

531+
/// {@macro flutter.material.textfield.restorationId}
532+
final String? restorationId;
533+
530534
@override
531535
State<DropdownMenu<T>> createState() => _DropdownMenuState<T>();
532536
}
@@ -1070,6 +1074,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
10701074
: null,
10711075
suffixIcon: trailingButton,
10721076
).applyDefaults(effectiveInputDecorationTheme),
1077+
restorationId: widget.restorationId,
10731078
);
10741079

10751080
// If [expandedInsets] is not null, the width of the text field should depend

packages/flutter/test/material/dropdown_menu_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,6 +4213,27 @@ void main() {
42134213

42144214
semantics.dispose();
42154215
});
4216+
4217+
testWidgets('restorationId is passed to inner TextField', (WidgetTester tester) async {
4218+
const String restorationId = 'dropdown_menu';
4219+
4220+
await tester.pumpWidget(
4221+
MaterialApp(
4222+
home: Scaffold(
4223+
body: DropdownMenu<TestMenu>(
4224+
dropdownMenuEntries: menuChildren,
4225+
requestFocusOnTap: true,
4226+
restorationId: restorationId,
4227+
),
4228+
),
4229+
),
4230+
);
4231+
4232+
expect(find.byType(TextField), findsOne);
4233+
4234+
final TextField textField = tester.firstWidget(find.byType(TextField));
4235+
expect(textField.restorationId, restorationId);
4236+
});
42164237
}
42174238

42184239
enum TestMenu {

0 commit comments

Comments
 (0)