Add DropdownMenu.restorationId (#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 https://github.com/flutter/flutter/pull/163721
## Tests
Adds 1 test.
diff --git a/packages/flutter/lib/src/material/dropdown_menu.dart b/packages/flutter/lib/src/material/dropdown_menu.dart
index 52326b9..1d8c0f0 100644
--- a/packages/flutter/lib/src/material/dropdown_menu.dart
+++ b/packages/flutter/lib/src/material/dropdown_menu.dart
@@ -190,6 +190,7 @@
this.closeBehavior = DropdownMenuCloseBehavior.all,
this.maxLines = 1,
this.textInputAction,
+ this.restorationId,
}) : assert(filterCallback == null || enableFilter);
/// Determine if the [DropdownMenu] is enabled.
@@ -527,6 +528,9 @@
/// {@macro flutter.widgets.TextField.textInputAction}
final TextInputAction? textInputAction;
+ /// {@macro flutter.material.textfield.restorationId}
+ final String? restorationId;
+
@override
State<DropdownMenu<T>> createState() => _DropdownMenuState<T>();
}
@@ -1070,6 +1074,7 @@
: null,
suffixIcon: trailingButton,
).applyDefaults(effectiveInputDecorationTheme),
+ restorationId: widget.restorationId,
);
// If [expandedInsets] is not null, the width of the text field should depend
diff --git a/packages/flutter/test/material/dropdown_menu_test.dart b/packages/flutter/test/material/dropdown_menu_test.dart
index 99123f4..073230a 100644
--- a/packages/flutter/test/material/dropdown_menu_test.dart
+++ b/packages/flutter/test/material/dropdown_menu_test.dart
@@ -4213,6 +4213,27 @@
semantics.dispose();
});
+
+ testWidgets('restorationId is passed to inner TextField', (WidgetTester tester) async {
+ const String restorationId = 'dropdown_menu';
+
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: DropdownMenu<TestMenu>(
+ dropdownMenuEntries: menuChildren,
+ requestFocusOnTap: true,
+ restorationId: restorationId,
+ ),
+ ),
+ ),
+ );
+
+ expect(find.byType(TextField), findsOne);
+
+ final TextField textField = tester.firstWidget(find.byType(TextField));
+ expect(textField.restorationId, restorationId);
+ });
}
enum TestMenu {