diff --git a/packages/flutter/test/material/autocomplete_test.dart b/packages/flutter/test/material/autocomplete_test.dart index 45f028bc02..4156a2f22c 100644 --- a/packages/flutter/test/material/autocomplete_test.dart +++ b/packages/flutter/test/material/autocomplete_test.dart @@ -459,9 +459,7 @@ void main() { const Color highlightColor = Color(0xFF112233); await tester.pumpWidget( MaterialApp( - theme: ThemeData.light(useMaterial3: false).copyWith( - focusColor: highlightColor, - ), + theme: ThemeData.light().copyWith(focusColor: highlightColor), home: Scaffold( body: Autocomplete( optionsBuilder: (TextEditingValue textEditingValue) { @@ -481,27 +479,39 @@ void main() { final ListView list = find.byType(ListView).evaluate().first.widget as ListView; expect(list.semanticChildCount, 6); - // Highlighted item should be at the top - expect(tester.getTopLeft(find.text('chameleon')).dy, equals(64.0)); - checkOptionHighlight(tester, 'chameleon', highlightColor); + final Rect optionsGroupRect = tester.getRect(find.byType(ListView)); + const double optionsGroupPadding = 16.0; - // Move down the list of options - await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); - await tester.pump(); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); - await tester.pump(); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); - await tester.pump(); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); - await tester.pump(); + // Highlighted item should be at the top. + checkOptionHighlight(tester, 'chameleon', highlightColor); + expect( + tester.getTopLeft(find.text('chameleon')).dy, + equals(optionsGroupRect.top + optionsGroupPadding), + ); + + // Move down the list of options. + await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); // Select 'elephant'. + await tester.pumpAndSettle(); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); // Select 'goose'. + await tester.pumpAndSettle(); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); // Select 'lemur'. + await tester.pumpAndSettle(); + + // Highlighted item 'lemur' should be centered in the options popup. + checkOptionHighlight(tester, 'lemur', highlightColor); + expect( + tester.getCenter(find.text('lemur')).dy, + equals(optionsGroupRect.center.dy), + ); + + await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); // Select 'mouse'. + await tester.pumpAndSettle(); + + checkOptionHighlight(tester, 'mouse', highlightColor); // First item should have scrolled off the top, and not be selected. expect(find.text('chameleon'), findsNothing); - // Highlighted item 'lemur' should be centered in the options popup - expect(tester.getTopLeft(find.text('mouse')).dy, equals(187.0)); - checkOptionHighlight(tester, 'mouse', highlightColor); - // The other items on screen should not be selected. checkOptionHighlight(tester, 'goose', null); checkOptionHighlight(tester, 'lemur', null);