From eee1cffceea3b53287c8097679a9c868c4831330 Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Thu, 17 Apr 2025 08:37:01 +0200 Subject: [PATCH] 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. --- .../lib/src/material/dropdown_menu.dart | 5 +++++ .../test/material/dropdown_menu_test.dart | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/flutter/lib/src/material/dropdown_menu.dart b/packages/flutter/lib/src/material/dropdown_menu.dart index 52326b95c2e..1d8c0f0e9ca 100644 --- a/packages/flutter/lib/src/material/dropdown_menu.dart +++ b/packages/flutter/lib/src/material/dropdown_menu.dart @@ -190,6 +190,7 @@ class DropdownMenu 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 extends StatefulWidget { /// {@macro flutter.widgets.TextField.textInputAction} final TextInputAction? textInputAction; + /// {@macro flutter.material.textfield.restorationId} + final String? restorationId; + @override State> createState() => _DropdownMenuState(); } @@ -1070,6 +1074,7 @@ class _DropdownMenuState extends State> { : 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 99123f4b2c4..073230aeaf0 100644 --- a/packages/flutter/test/material/dropdown_menu_test.dart +++ b/packages/flutter/test/material/dropdown_menu_test.dart @@ -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( + 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 {