diff --git a/packages/flutter/lib/src/material/dropdown_menu.dart b/packages/flutter/lib/src/material/dropdown_menu.dart index 97e89fd40b..a6cb62cff4 100644 --- a/packages/flutter/lib/src/material/dropdown_menu.dart +++ b/packages/flutter/lib/src/material/dropdown_menu.dart @@ -592,7 +592,7 @@ class _DropdownMenuState extends State> { WidgetsBinding.instance.addPostFrameCallback((_) { final BuildContext? highlightContext = buttonItemKeys[currentHighlight!].currentContext; if (highlightContext != null) { - Scrollable.ensureVisible(highlightContext); + Scrollable.of(highlightContext).position.ensureVisible(highlightContext.findRenderObject()!); } }, debugLabel: 'DropdownMenu.scrollToHighlight'); } diff --git a/packages/flutter/test/material/dropdown_menu_test.dart b/packages/flutter/test/material/dropdown_menu_test.dart index c285513e3a..b1527427a2 100644 --- a/packages/flutter/test/material/dropdown_menu_test.dart +++ b/packages/flutter/test/material/dropdown_menu_test.dart @@ -2723,6 +2723,36 @@ void main() { ), ); }); + + // This is a regression test for https://github.com/flutter/flutter/issues/151854. + testWidgets('scrollToHighlight does not scroll parent', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: ListView( + controller: controller, + children: [ + ListView( + shrinkWrap: true, + children: [DropdownMenu( + initialSelection: menuChildren.last.value, + dropdownMenuEntries: menuChildren, + )], + ), + const SizedBox(height: 1000.0), + ], + ), + ), + ), + ); + + await tester.tap(find.byType(TextField).first); + await tester.pumpAndSettle(); + expect(controller.offset, 0.0); + }); } enum TestMenu {