mirror of
https://github.com/flutter/flutter.git
synced 2026-02-14 23:02:04 +08:00
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:
parent
af2e73343a
commit
eee1cffcee
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user