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.
This commit is contained in:
Bruno Leroux 2025-04-17 08:37:01 +02:00 committed by GitHub
parent af2e73343a
commit eee1cffcee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View File

@ -190,6 +190,7 @@ class DropdownMenu<T> extends StatefulWidget {
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 @@ class DropdownMenu<T> extends StatefulWidget {
/// {@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 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
: null,
suffixIcon: trailingButton,
).applyDefaults(effectiveInputDecorationTheme),
restorationId: widget.restorationId,
);
// If [expandedInsets] is not null, the width of the text field should depend

View File

@ -4213,6 +4213,27 @@ void main() {
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 {