diff --git a/dev/integration_tests/flutter_gallery/test/live_smoketest.dart b/dev/integration_tests/flutter_gallery/test/live_smoketest.dart index e90a66782c4..6b83d78b080 100644 --- a/dev/integration_tests/flutter_gallery/test/live_smoketest.dart +++ b/dev/integration_tests/flutter_gallery/test/live_smoketest.dart @@ -132,8 +132,8 @@ class _LiveWidgetController extends LiveWidgetController { } @override - Future tap(Finder finder, { int? pointer, int buttons = kPrimaryButton }) async { - await super.tap(await _waitForElement(finder), pointer: pointer, buttons: buttons); + Future tap(Finder finder, { int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true }) async { + await super.tap(await _waitForElement(finder), pointer: pointer, buttons: buttons, warnIfMissed: warnIfMissed); } Future scrollIntoView(Finder finder, {required double alignment}) async { diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index a25b71fc536..db739a06b2d 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -3514,10 +3514,10 @@ class RenderMetaData extends RenderProxyBoxWithHitTestBehavior { /// Listens for the specified gestures from the semantics server (e.g. /// an accessibility tool). -class RenderSemanticsGestureHandler extends RenderProxyBox { +class RenderSemanticsGestureHandler extends RenderProxyBoxWithHitTestBehavior { /// Creates a render object that listens for specific semantic gestures. /// - /// The [scrollFactor] argument must not be null. + /// The [scrollFactor] and [behavior] arguments must not be null. RenderSemanticsGestureHandler({ RenderBox? child, GestureTapCallback? onTap, @@ -3525,12 +3525,13 @@ class RenderSemanticsGestureHandler extends RenderProxyBox { GestureDragUpdateCallback? onHorizontalDragUpdate, GestureDragUpdateCallback? onVerticalDragUpdate, this.scrollFactor = 0.8, + HitTestBehavior behavior = HitTestBehavior.deferToChild, }) : assert(scrollFactor != null), _onTap = onTap, _onLongPress = onLongPress, _onHorizontalDragUpdate = onHorizontalDragUpdate, _onVerticalDragUpdate = onVerticalDragUpdate, - super(child); + super(behavior: behavior, child: child); /// If non-null, the set of actions to allow. Other actions will be omitted, /// even if their callback is provided. diff --git a/packages/flutter/lib/src/widgets/gesture_detector.dart b/packages/flutter/lib/src/widgets/gesture_detector.dart index de67272d026..4fe6e001a38 100644 --- a/packages/flutter/lib/src/widgets/gesture_detector.dart +++ b/packages/flutter/lib/src/widgets/gesture_detector.dart @@ -1221,11 +1221,13 @@ class RawGestureDetectorState extends State { behavior: widget.behavior ?? _defaultBehavior, child: widget.child, ); - if (!widget.excludeFromSemantics) + if (!widget.excludeFromSemantics) { result = _GestureSemantics( - child: result, + behavior: widget.behavior ?? _defaultBehavior, assignSemantics: _updateSemanticsForRenderObject, + child: result, ); + } return result; } @@ -1253,21 +1255,25 @@ class _GestureSemantics extends SingleChildRenderObjectWidget { const _GestureSemantics({ Key? key, Widget? child, + required this.behavior, required this.assignSemantics, }) : assert(assignSemantics != null), super(key: key, child: child); + final HitTestBehavior behavior; final _AssignSemantics assignSemantics; @override RenderSemanticsGestureHandler createRenderObject(BuildContext context) { - final RenderSemanticsGestureHandler renderObject = RenderSemanticsGestureHandler(); + final RenderSemanticsGestureHandler renderObject = RenderSemanticsGestureHandler() + ..behavior = behavior; assignSemantics(renderObject); return renderObject; } @override void updateRenderObject(BuildContext context, RenderSemanticsGestureHandler renderObject) { + renderObject.behavior = behavior; assignSemantics(renderObject); } } diff --git a/packages/flutter/test/cupertino/action_sheet_test.dart b/packages/flutter/test/cupertino/action_sheet_test.dart index 27b91868e0e..4d88b3132e0 100644 --- a/packages/flutter/test/cupertino/action_sheet_test.dart +++ b/packages/flutter/test/cupertino/action_sheet_test.dart @@ -39,6 +39,7 @@ void main() { await tester.tap(find.text('Go')); await tester.pump(); + await tester.pump(const Duration(seconds: 5)); expect(find.text('Action Sheet'), findsOneWidget); diff --git a/packages/flutter/test/cupertino/date_picker_test.dart b/packages/flutter/test/cupertino/date_picker_test.dart index a6790975356..91b4cece279 100644 --- a/packages/flutter/test/cupertino/date_picker_test.dart +++ b/packages/flutter/test/cupertino/date_picker_test.dart @@ -8,6 +8,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +// A number of the hit tests below say "warnIfMissed: false". This is because +// the way the CupertinoPicker works, the hits don't actually reach the labels, +// the scroll view intercepts them. + // scrolling by this offset will move the picker to the next item const Offset _kRowOffset = Offset(0.0, -50.0); @@ -251,10 +255,9 @@ void main() { ), ), ); - - await tester.drag(find.text('40'), _kRowOffset); + await tester.drag(find.text('40'), _kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); - await tester.drag(find.text('48'), -_kRowOffset); + await tester.drag(find.text('48'), -_kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); @@ -333,7 +336,7 @@ void main() { // Drag the minute picker to the next slot (03 -> 06). // The `initialDateTime` and the `minuteInterval` values are specifically chosen // so that `find.text` finds exactly one widget. - await tester.drag(find.text('03'), _kRowOffset); + await tester.drag(find.text('03'), _kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); expect(newDateTime.minute, 6); @@ -379,7 +382,7 @@ void main() { ), ); - await tester.drag(find.text('10'), const Offset(0.0, 32.0), touchSlopY: 0); + await tester.drag(find.text('10'), const Offset(0.0, 32.0), touchSlopY: 0, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); @@ -402,7 +405,7 @@ void main() { ), ); - await tester.drag(find.text('9'), const Offset(0.0, 32.0), touchSlopY: 0); + await tester.drag(find.text('9'), const Offset(0.0, 32.0), touchSlopY: 0, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); @@ -604,7 +607,7 @@ void main() { ), ); - await tester.drag(find.text('March'), const Offset(0, 32.0), touchSlopY: 0.0); + await tester.drag(find.text('March'), const Offset(0, 32.0), touchSlopY: 0.0, warnIfMissed: false); // see top of file // Momentarily, the 2018 and the incorrect 30 of February is aligned. expect( @@ -662,7 +665,7 @@ void main() { isSameColorAs(CupertinoColors.inactiveGray.color), ); - await tester.drag(find.text('2017'), const Offset(0.0, 32.0), touchSlopY: 0.0); + await tester.drag(find.text('2017'), const Offset(0.0, 32.0), touchSlopY: 0.0, warnIfMissed: false); // see top of file await tester.pump(); await tester.pumpAndSettle(); // Now the autoscrolling should happen. @@ -677,7 +680,7 @@ void main() { isNot(isSameColorAs(CupertinoColors.inactiveGray.color)), ); - await tester.drag(find.text('2016'), const Offset(0.0, -32.0), touchSlopY: 0.0); + await tester.drag(find.text('2016'), const Offset(0.0, -32.0), touchSlopY: 0.0, warnIfMissed: false); // see top of file await tester.pump(); // Once to trigger the post frame animate call. await tester.pumpAndSettle(); @@ -739,7 +742,7 @@ void main() { isSameColorAs(CupertinoColors.inactiveGray.color), ); - await tester.drag(find.text('AM'), const Offset(0.0, -32.0), touchSlopY: 0.0); + await tester.drag(find.text('AM'), const Offset(0.0, -32.0), touchSlopY: 0.0, warnIfMissed: false); // see top of file await tester.pump(); await tester.pumpAndSettle(); // Now the autoscrolling should happen. @@ -758,7 +761,7 @@ void main() { isSameColorAs(CupertinoColors.inactiveGray.color), ); - await tester.drag(find.text('PM'), const Offset(0.0, 32.0), touchSlopY: 0.0); + await tester.drag(find.text('PM'), const Offset(0.0, 32.0), touchSlopY: 0.0, warnIfMissed: false); // see top of file await tester.pump(); // Once to trigger the post frame animate call. await tester.pumpAndSettle(); @@ -816,7 +819,7 @@ void main() { isSameColorAs(CupertinoColors.inactiveGray.color), ); - await tester.drag(find.text('AM'), const Offset(0.0, -32.0), touchSlopY: 0.0); + await tester.drag(find.text('AM'), const Offset(0.0, -32.0), touchSlopY: 0.0, warnIfMissed: false); // see top of file await tester.pump(); await tester.pumpAndSettle(); // Now the autoscrolling should happen. @@ -835,7 +838,7 @@ void main() { isSameColorAs(CupertinoColors.inactiveGray.color), ); - await tester.drag(find.text('PM'), const Offset(0.0, 32.0), touchSlopY: 0.0); + await tester.drag(find.text('PM'), const Offset(0.0, 32.0), touchSlopY: 0.0, warnIfMissed: false); // see top of file await tester.pump(); // Once to trigger the post frame animate call. await tester.pumpAndSettle(); @@ -866,14 +869,14 @@ void main() { ), ); - await tester.drag(find.text('27'), const Offset(0.0, -32.0), touchSlopY: 0.0); + await tester.drag(find.text('27'), const Offset(0.0, -32.0), touchSlopY: 0.0, warnIfMissed: false); // see top of file await tester.pump(); expect( date, DateTime(2018, 2, 28), ); - await tester.drag(find.text('28'), const Offset(0.0, -32.0), touchSlopY: 0.0); + await tester.drag(find.text('28'), const Offset(0.0, -32.0), touchSlopY: 0.0, warnIfMissed: false); // see top of file await tester.pump(); // Once to trigger the post frame animate call. // Callback doesn't transiently go into invalid dates. @@ -924,7 +927,7 @@ void main() { ); // Scroll to 2019. - await tester.drag(find.text('2020'), const Offset(0.0, 32.0), touchSlopY: 0.0); + await tester.drag(find.text('2020'), const Offset(0.0, 32.0), touchSlopY: 0.0, warnIfMissed: false); // see top of file await tester.pump(); await tester.pumpAndSettle(); expect(date.year, minDate.year); @@ -978,7 +981,7 @@ void main() { ); // 0:15 -> 0:16 - await tester.drag(find.text('15'), _kRowOffset); + await tester.drag(find.text('15'), _kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); @@ -1006,7 +1009,7 @@ void main() { ); // 12:15 -> 12:16 - await tester.drag(find.text('15'), _kRowOffset); + await tester.drag(find.text('15'), _kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); @@ -1035,7 +1038,7 @@ void main() { ); // 12:25 -> 12:26 - await tester.drag(find.text('25'), _kRowOffset); + await tester.drag(find.text('25'), _kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); @@ -1064,28 +1067,28 @@ void main() { ); // 3:00 -> 15:00 - await tester.drag(find.text('AM'), _kRowOffset); + await tester.drag(find.text('AM'), _kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); expect(date, DateTime(2019, 1, 1, 15)); // 15:00 -> 16:00 - await tester.drag(find.text('3'), _kRowOffset); + await tester.drag(find.text('3'), _kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); expect(date, DateTime(2019, 1, 1, 16)); // 16:00 -> 4:00 - await tester.drag(find.text('PM'), -_kRowOffset); + await tester.drag(find.text('PM'), -_kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); expect(date, DateTime(2019, 1, 1, 4)); // 4:00 -> 3:00 - await tester.drag(find.text('4'), -_kRowOffset); + await tester.drag(find.text('4'), -_kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); @@ -1115,28 +1118,28 @@ void main() { const Offset deltaOffset = Offset(0.0, -18.0); // 11:59 -> 12:59 - await tester.drag(find.text('11'), _kRowOffset); + await tester.drag(find.text('11'), _kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); expect(date, DateTime(2018, 1, 1, 12, 59)); // 12:59 -> 11:59 - await tester.drag(find.text('12'), -_kRowOffset); + await tester.drag(find.text('12'), -_kRowOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); expect(date, DateTime(2018, 1, 1, 11, 59)); // 11:59 -> 9:59 - await tester.drag(find.text('11'), -((_kRowOffset - deltaOffset) * 2 + deltaOffset)); + await tester.drag(find.text('11'), -((_kRowOffset - deltaOffset) * 2 + deltaOffset), warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); expect(date, DateTime(2018, 1, 1, 9, 59)); // 9:59 -> 15:59 - await tester.drag(find.text('9'), (_kRowOffset - deltaOffset) * 6 + deltaOffset); + await tester.drag(find.text('9'), (_kRowOffset - deltaOffset) * 6 + deltaOffset, warnIfMissed: false); // see top of file await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); @@ -1207,7 +1210,7 @@ void main() { ); // Slightly drag the hour component to make the current hour off-center. - await tester.drag(find.text('4'), Offset(0, _kRowOffset.dy / 2)); + await tester.drag(find.text('4'), Offset(0, _kRowOffset.dy / 2), warnIfMissed: false); // see top of file await tester.pump(); await expectLater( @@ -1276,7 +1279,7 @@ void main() { ); // Slightly drag the minute component to make the current minute off-center. - await tester.drag(find.text('59'), Offset(0, _kRowOffset.dy / 2)); + await tester.drag(find.text('59'), Offset(0, _kRowOffset.dy / 2), warnIfMissed: false); // see top of file await tester.pump(); await expectLater( @@ -1307,7 +1310,7 @@ void main() { expect(find.text('hour'), findsNothing); expect(find.text('hours'), findsOneWidget); - await tester.drag(find.text('2'), Offset(0, -_kRowOffset.dy)); + await tester.drag(find.text('2'), Offset(0, -_kRowOffset.dy), warnIfMissed: false); // see top of file // Duration should change but not the label. expect(duration!.inHours, 1); expect(find.text('hour'), findsNothing); diff --git a/packages/flutter/test/cupertino/picker_test.dart b/packages/flutter/test/cupertino/picker_test.dart index 5f65ff0195d..878076ae717 100644 --- a/packages/flutter/test/cupertino/picker_test.dart +++ b/packages/flutter/test/cupertino/picker_test.dart @@ -202,7 +202,7 @@ void main() { ), ); - await tester.drag(find.text('0'), const Offset(0.0, -100.0)); + await tester.drag(find.text('0'), const Offset(0.0, -100.0), warnIfMissed: false); // has an IgnorePointer expect(selectedItems, [1]); expect( systemCalls.single, @@ -212,7 +212,7 @@ void main() { ), ); - await tester.drag(find.text('0'), const Offset(0.0, 100.0)); + await tester.drag(find.text('0'), const Offset(0.0, 100.0), warnIfMissed: false); // has an IgnorePointer expect(selectedItems, [1, 0]); expect(systemCalls, hasLength(2)); expect( @@ -253,7 +253,7 @@ void main() { ), ); - await tester.drag(find.text('0'), const Offset(0.0, -100.0)); + await tester.drag(find.text('0'), const Offset(0.0, -100.0), warnIfMissed: false); // has an IgnorePointer expect(selectedItems, [1]); expect(systemCalls, isEmpty); }, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform platform) => platform != TargetPlatform.iOS).toSet())); @@ -284,7 +284,7 @@ void main() { ); // Drag it by a bit but not enough to move to the next item. - await tester.drag(find.text('10'), const Offset(0.0, 30.0), touchSlopY: 0.0); + await tester.drag(find.text('10'), const Offset(0.0, 30.0), touchSlopY: 0.0, warnIfMissed: false); // has an IgnorePointer // The item that was in the center now moved a bit. expect( @@ -301,7 +301,7 @@ void main() { expect(selectedItems.isEmpty, true); // Drag it by enough to move to the next item. - await tester.drag(find.text('10'), const Offset(0.0, 70.0), touchSlopY: 0.0); + await tester.drag(find.text('10'), const Offset(0.0, 70.0), touchSlopY: 0.0, warnIfMissed: false); // has an IgnorePointer await tester.pumpAndSettle(); @@ -343,6 +343,7 @@ void main() { find.text('10'), const Offset(0.0, 10000.0), 1000.0, + warnIfMissed: false, // has an IgnorePointer ); // Should have been flung far enough that even the first item goes off diff --git a/packages/flutter/test/cupertino/refresh_test.dart b/packages/flutter/test/cupertino/refresh_test.dart index 457ba655850..c254d10c248 100644 --- a/packages/flutter/test/cupertino/refresh_test.dart +++ b/packages/flutter/test/cupertino/refresh_test.dart @@ -412,7 +412,7 @@ void main() { const Rect.fromLTRB(0.0, 0.0, 800.0, 150.0), ); - await tester.drag(find.text('0'), const Offset(0.0, -300.0), touchSlopY: 0); + await tester.drag(find.text('0'), const Offset(0.0, -300.0), touchSlopY: 0, warnIfMissed: false); // hits the list await tester.pump(); // Refresh indicator still being told to layout the same way. @@ -439,7 +439,7 @@ void main() { // Scroll the top of the refresh indicator back to overscroll, it will // snap to the size of the refresh indicator and stay there. - await tester.drag(find.text('1'), const Offset(0.0, 200.0)); + await tester.drag(find.text('1'), const Offset(0.0, 200.0), warnIfMissed: false); // hits the list await tester.pump(); await tester.pump(const Duration(seconds: 2)); expect( @@ -652,7 +652,7 @@ void main() { // Start another drag by an amount that would have been enough to // trigger another refresh if it were in the right state. - await tester.drag(find.text('0'), const Offset(0.0, 150.0), touchSlopY: 0.0); + await tester.drag(find.text('0'), const Offset(0.0, 150.0), touchSlopY: 0.0, warnIfMissed: false); await tester.pump(); // Instead, it's still in the done state because the sliver never @@ -841,8 +841,7 @@ void main() { ); await tester.fling(find.byType(Container).first, const Offset(0.0, 200.0), 2000.0); - - await tester.fling(find.byType(Container).first, const Offset(0.0, -200.0), 3000.0); + await tester.fling(find.byType(Container).first, const Offset(0.0, -200.0), 3000.0, warnIfMissed: false); // IgnorePointer is enabled while scroll is ballistic. expect(mockHelper.invocations, isEmpty); }, variant: const TargetPlatformVariant({ TargetPlatform.iOS, TargetPlatform.macOS })); diff --git a/packages/flutter/test/cupertino/route_test.dart b/packages/flutter/test/cupertino/route_test.dart index 8be43149f04..a2a187e87b9 100644 --- a/packages/flutter/test/cupertino/route_test.dart +++ b/packages/flutter/test/cupertino/route_test.dart @@ -545,7 +545,7 @@ void main() { expect(tester.getTopLeft(find.byType(Placeholder)).dx, moreOrLessEquals(-267.0, epsilon: 1.0)); // Exit animation - await tester.tap(find.text('Button')); + await tester.tap(find.text('Close')); await tester.pump(); await tester.pump(const Duration(milliseconds: 40)); @@ -634,7 +634,7 @@ void main() { expect(tester.getTopLeft(find.byType(Placeholder)).dx, 0.0); // Exit animation - await tester.tap(find.text('Button')); + await tester.tap(find.text('Close')); await tester.pump(); await tester.pump(const Duration(milliseconds: 40)); @@ -1068,7 +1068,7 @@ void main() { // Tapping on the "page" route doesn't trigger the GestureDetector because // it's being dragged. - await tester.tap(find.byKey(pageScaffoldKey)); + await tester.tap(find.byKey(pageScaffoldKey), warnIfMissed: false); expect(homeTapCount, 1); expect(pageTapCount, 1); }); diff --git a/packages/flutter/test/cupertino/scaffold_test.dart b/packages/flutter/test/cupertino/scaffold_test.dart index 6654a0f3099..20c34184db2 100644 --- a/packages/flutter/test/cupertino/scaffold_test.dart +++ b/packages/flutter/test/cupertino/scaffold_test.dart @@ -282,7 +282,7 @@ void main() { expect(tester.getTopLeft(find.byWidget(content)).dy, 20.0 + 44.0); // Overscroll to the bottom. - await tester.drag(find.byWidget(content), const Offset(0.0, -400.0)); + await tester.drag(find.byWidget(content), const Offset(0.0, -400.0), warnIfMissed: false); // can't be hit (it's empty) but we're aiming for the list really so it doesn't matter // Let it bounce back. await tester.pump(); await tester.pump(const Duration(seconds: 1)); diff --git a/packages/flutter/test/cupertino/slider_test.dart b/packages/flutter/test/cupertino/slider_test.dart index 2afed420ad8..d9022318d43 100644 --- a/packages/flutter/test/cupertino/slider_test.dart +++ b/packages/flutter/test/cupertino/slider_test.dart @@ -59,7 +59,7 @@ void main() { ); expect(value, equals(0.0)); - await tester.tap(find.byKey(sliderKey)); + await tester.tap(find.byKey(sliderKey), warnIfMissed: false); expect(value, equals(0.0)); await tester.pump(); // No animation should start. // Check the transientCallbackCount before tearing down the widget to ensure @@ -95,7 +95,7 @@ void main() { ); expect(value, equals(0.0)); - await tester.tap(find.byKey(sliderKey)); + await tester.tap(find.byKey(sliderKey), warnIfMissed: false); expect(value, equals(0.0)); await tester.pump(); // No animation should start. // Check the transientCallbackCount before tearing down the widget to ensure diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index 838c77c1213..d87898cfce4 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -1547,7 +1547,7 @@ void main() { expect(find.text('field 1'), findsOneWidget); expect(find.text('field 2'), findsOneWidget); - await tester.longPress(find.text('field 2')); + await tester.longPress(find.text('field 2'), warnIfMissed: false); // can't actually hit placeholder await tester.pump(); await tester.pump(const Duration(milliseconds: 200)); @@ -2981,7 +2981,7 @@ void main() { ); expect(tapCount, 0); - await tester.tap(find.byType(CupertinoTextField)); + await tester.tap(find.byType(CupertinoTextField), warnIfMissed: false); // disabled await tester.pump(); expect(tapCount, 0); @@ -3016,7 +3016,7 @@ void main() { ), ), ); - await tester.tap(find.byType(CupertinoTextField)); + await tester.tap(find.byType(CupertinoTextField), warnIfMissed: false); // disabled await tester.pump(); expect(tapCount, 1); }); diff --git a/packages/flutter/test/cupertino/text_form_field_row_test.dart b/packages/flutter/test/cupertino/text_form_field_row_test.dart index 55a59a5ed2d..fc53024dda8 100644 --- a/packages/flutter/test/cupertino/text_form_field_row_test.dart +++ b/packages/flutter/test/cupertino/text_form_field_row_test.dart @@ -252,10 +252,11 @@ void main() { await tester.pump(); expect(tester.testTextInput.hasAnyClients, false); - await tester.longPress(find.byType(CupertinoTextFormFieldRow)); + await tester.longPress(find.text('readonly')); await tester.pump(); // Context menu should not have paste. + expect(find.byType(CupertinoTextSelectionToolbar), findsOneWidget); expect(find.text('Paste'), findsNothing); final EditableTextState editableTextState = diff --git a/packages/flutter/test/flutter_test_config.dart b/packages/flutter/test/flutter_test_config.dart index dfe58ff815c..5cd25242d1d 100644 --- a/packages/flutter/test/flutter_test_config.dart +++ b/packages/flutter/test/flutter_test_config.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; import '_goldens_io.dart' if (dart.library.html) '_goldens_web.dart' as flutter_goldens; @@ -14,5 +15,10 @@ Future testExecutable(FutureOr testMain()) { // package can benefit from the additional validations. debugCheckIntrinsicSizes = true; + // Make tap() et al fail if the given finder specifies a widget that would not + // receive the event. + WidgetController.hitTestWarningShouldBeFatal = true; + + // Enable golden file testing using Skia Gold. return flutter_goldens.testExecutable(testMain); } diff --git a/packages/flutter/test/material/bottom_sheet_test.dart b/packages/flutter/test/material/bottom_sheet_test.dart index 819feb197bb..32f25ad41ae 100644 --- a/packages/flutter/test/material/bottom_sheet_test.dart +++ b/packages/flutter/test/material/bottom_sheet_test.dart @@ -734,6 +734,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { showModalBottomSheet( context: context, @@ -754,7 +755,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); }, @@ -793,6 +793,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { showBottomSheet( context: context, @@ -817,7 +818,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); }, diff --git a/packages/flutter/test/material/chip_test.dart b/packages/flutter/test/material/chip_test.dart index ab26930774a..69f49c36414 100644 --- a/packages/flutter/test/material/chip_test.dart +++ b/packages/flutter/test/material/chip_test.dart @@ -881,8 +881,8 @@ void main() { }); testWidgets('Delete button drawer works as expected on RawChip', (WidgetTester tester) async { - final UniqueKey labelKey = UniqueKey(); - final UniqueKey deleteButtonKey = UniqueKey(); + const Key labelKey = Key('label'); + const Key deleteButtonKey = Key('delete'); bool wasDeleted = false; Future pushChip({ bool deletable = false }) async { return tester.pumpWidget( @@ -898,8 +898,8 @@ void main() { }); } : null, - deleteIcon: Container(width: 40.0, height: 40.0, key: deleteButtonKey), - label: Text('Chip', key: labelKey), + deleteIcon: Container(width: 40.0, height: 40.0, color: Colors.blue, key: deleteButtonKey), + label: const Text('Chip', key: labelKey), shape: const StadiumBorder(), ); }), diff --git a/packages/flutter/test/material/date_picker_test.dart b/packages/flutter/test/material/date_picker_test.dart index ce7b8151d3b..e9c193097d0 100644 --- a/packages/flutter/test/material/date_picker_test.dart +++ b/packages/flutter/test/material/date_picker_test.dart @@ -326,8 +326,8 @@ void main() { ), ), ); - await tester.tap(find.text('X')); - await tester.pumpAndSettle(); + await tester.pump(); // start theme animation + await tester.pump(const Duration(seconds: 5)); // end theme animation final Material themeDialogMaterial = tester.widget(find.descendant(of: find.byType(Dialog), matching: find.byType(Material)).first); expect(themeDialogMaterial.shape, customDialogTheme.shape); expect(themeDialogMaterial.elevation, customDialogTheme.elevation); diff --git a/packages/flutter/test/material/dropdown_test.dart b/packages/flutter/test/material/dropdown_test.dart index b90d03bcd1b..86c24340ee9 100644 --- a/packages/flutter/test/material/dropdown_test.dart +++ b/packages/flutter/test/material/dropdown_test.dart @@ -360,7 +360,7 @@ void main() { expect(value, equals('three')); - await tester.tap(find.text('three')); + await tester.tap(find.text('three'), warnIfMissed: false); await tester.pump(); await tester.pump(const Duration(seconds: 1)); // finish the menu animation @@ -416,7 +416,7 @@ void main() { expect(value, equals('three')); - await tester.tap(find.text('three')); + await tester.tap(find.text('three'), warnIfMissed: false); await tester.pump(); await tester.pump(const Duration(seconds: 1)); // finish the menu animation @@ -539,7 +539,7 @@ void main() { // Initial value of null displays hint expect(value, equals(null)); expect(getIndex(), 4); - await tester.tap(find.text('Select Value')); + await tester.tap(find.text('Select Value'), warnIfMissed: false); await tester.pumpAndSettle(); await tester.tap(find.text('three').last); await tester.pumpAndSettle(); @@ -671,7 +671,7 @@ void main() { expect(tester.elementList(find.text('19')), hasLength(1)); expect(value, 4); - await tester.tap(find.byWidget(button)); + await tester.tap(find.byWidget(button), warnIfMissed: false); expect(value, 4); // this waits for the route's completer to complete, which calls handleChanged await tester.idle(); @@ -1095,7 +1095,7 @@ void main() { await tester.pump(const Duration(seconds: 1)); // finish the menu animation // Tap on item 'one', which must appear over the button. - await tester.tap(find.byKey(buttonKey)); + await tester.tap(find.byKey(buttonKey), warnIfMissed: false); await tester.pump(); await tester.pump(const Duration(seconds: 1)); // finish the menu animation @@ -1165,7 +1165,7 @@ void main() { await tester.pumpAndSettle(); menuRect = getMenuRect(); buttonRect = getExpandedButtonRect(); - await tester.tap(find.byType(dropdownButtonType)); + await tester.tap(find.byType(dropdownButtonType), warnIfMissed: false); } // Dropdown button is along the top of the app. The top of the menu is @@ -2166,7 +2166,7 @@ void main() { // Initially shows the hint text expect(find.text('Please select an item'), findsOneWidget); - await tester.tap(find.text('Please select an item')); + await tester.tap(find.text('Please select an item'), warnIfMissed: false); await tester.pumpAndSettle(); await tester.tap(find.text('1')); await tester.pumpAndSettle(); @@ -2392,7 +2392,7 @@ void main() { expect(tester.getTopLeft(find.text('-item0-')).dx, 8); // Show the popup menu. - await tester.tap(find.text('-item0-')); + await tester.tap(find.text('-item0-'), warnIfMissed: false); await tester.pumpAndSettle(); expect(tester.getTopLeft(find.text('-item0-')).dx, 8); @@ -2773,7 +2773,7 @@ void main() { expect(dropdownButtonTapCounter, 1); // Should not change. // Tap dropdown button again. - await tester.tap(find.text('three')); + await tester.tap(find.text('three'), warnIfMissed: false); await tester.pumpAndSettle(); expect(value, equals('three')); @@ -2839,7 +2839,7 @@ void main() { expect(menuItemTapCounters, [0, 0, 1, 0]); // Tap dropdown button again. - await tester.tap(find.text('three')); + await tester.tap(find.text('three'), warnIfMissed: false); await tester.pumpAndSettle(); // Should not change. @@ -2855,7 +2855,7 @@ void main() { expect(menuItemTapCounters, [0, 1, 1, 0]); // Tap dropdown button again. - await tester.tap(find.text('two')); + await tester.tap(find.text('two'), warnIfMissed: false); await tester.pumpAndSettle(); // Should not change. diff --git a/packages/flutter/test/material/flexible_space_bar_test.dart b/packages/flutter/test/material/flexible_space_bar_test.dart index b246c197b54..f8fc07d6c17 100644 --- a/packages/flutter/test/material/flexible_space_bar_test.dart +++ b/packages/flutter/test/material/flexible_space_bar_test.dart @@ -71,10 +71,13 @@ void main() { ), ) as FlexibleSpaceBarSettings; + const Key dragTarget = Key('orange box'); + await tester.pumpWidget( MaterialApp( home: Scaffold( body: CustomScrollView( + key: dragTarget, primary: true, slivers: [ SliverPersistentHeader( @@ -112,7 +115,7 @@ void main() { expect(effectiveStyle.color?.alpha, 128); // Which is alpha of .5 // We drag up to fully collapse the space bar. - await tester.drag(find.byType(Container).first, const Offset(0, -400.0)); + await tester.drag(find.byKey(dragTarget), const Offset(0, -400.0)); await tester.pumpAndSettle(); expect(clipRect.size.height, minExtent); diff --git a/packages/flutter/test/material/page_test.dart b/packages/flutter/test/material/page_test.dart index 0bccee7305a..cd92c421b21 100644 --- a/packages/flutter/test/material/page_test.dart +++ b/packages/flutter/test/material/page_test.dart @@ -701,12 +701,12 @@ void main() { // Tapping on the "page" route doesn't trigger the GestureDetector because // it's being dragged. - await tester.tap(find.byKey(pageScaffoldKey)); + await tester.tap(find.byKey(pageScaffoldKey), warnIfMissed: false); expect(homeTapCount, 1); expect(pageTapCount, 1); // Tapping the "page" route's back button doesn't do anything either. - await tester.tap(find.byTooltip('Back')); + await tester.tap(find.byTooltip('Back'), warnIfMissed: false); await tester.pumpAndSettle(); expect(tester.getTopLeft(find.byKey(pageScaffoldKey)), const Offset(400, 0)); expect(tester.getTopLeft(find.byKey(homeScaffoldKey)).dx, lessThan(0)); diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index 3d9bc9f9c38..4785d1c17d1 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -332,7 +332,7 @@ void main() { itemBuilderCalled = false; // Close the popup. - await tester.tap(find.byKey(popupButtonKey)); + await tester.tap(find.byKey(popupButtonKey), warnIfMissed: false); await tester.pumpAndSettle(); await tester.pumpWidget( @@ -768,7 +768,7 @@ void main() { testWidgets('Popup Menu Offset Test', (WidgetTester tester) async { PopupMenuButton buildMenuButton({Offset offset = Offset.zero}) { - return PopupMenuButton( + return PopupMenuButton( placement: PopupMenuPlacement.belowButton, offset: offset, itemBuilder: (BuildContext context) { @@ -807,7 +807,7 @@ void main() { expect(tester.getTopLeft(find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_PopupMenu')), Offset(8.0, iconSize.height)); // Collapse the menu. - await tester.tap(find.byType(IconButton)); + await tester.tap(find.byType(IconButton), warnIfMissed: false); await tester.pumpAndSettle(); // Popup a new menu with Offset(50.0, 50.0). @@ -1965,35 +1965,46 @@ void main() { } testWidgets('PopupMenuButton enableFeedback works properly', (WidgetTester tester) async { - //PopupMenuButton with enabled feedback + expect(feedback.clickSoundCount, 0); + expect(feedback.hapticCount, 0); + + // PopupMenuButton with enabled feedback. await tester.pumpWidget(buildFrame(widgetEnableFeedack: true)); await tester.tap(find.text('Show Menu')); await tester.pumpAndSettle(); expect(feedback.clickSoundCount, 1); expect(feedback.hapticCount, 0); - //PopupMenuButton with disabled feedback + await tester.pumpWidget(Container()); + + // PopupMenuButton with disabled feedback. await tester.pumpWidget(buildFrame(widgetEnableFeedack: false)); await tester.tap(find.text('Show Menu')); await tester.pumpAndSettle(); expect(feedback.clickSoundCount, 1); expect(feedback.hapticCount, 0); - //PopupMenuButton with enabled feedback by default + await tester.pumpWidget(Container()); + + // PopupMenuButton with enabled feedback by default. await tester.pumpWidget(buildFrame()); await tester.tap(find.text('Show Menu')); await tester.pumpAndSettle(); expect(feedback.clickSoundCount, 2); expect(feedback.hapticCount, 0); - //PopupMenu with disabled feedback using PopupMenuButtonTheme + await tester.pumpWidget(Container()); + + // PopupMenu with disabled feedback using PopupMenuButtonTheme. await tester.pumpWidget(buildFrame(themeEnableFeedback: false)); await tester.tap(find.text('Show Menu')); await tester.pumpAndSettle(); expect(feedback.clickSoundCount, 2); expect(feedback.hapticCount, 0); - //PopupMenu enableFeedback property overrides PopupMenuButtonTheme + await tester.pumpWidget(Container()); + + // PopupMenu enableFeedback property overrides PopupMenuButtonTheme. await tester.pumpWidget(buildFrame(widgetEnableFeedack: false,themeEnableFeedback: true)); await tester.tap(find.text('Show Menu')); await tester.pumpAndSettle(); diff --git a/packages/flutter/test/material/refresh_indicator_test.dart b/packages/flutter/test/material/refresh_indicator_test.dart index 010b0ea119c..2693db14e49 100644 --- a/packages/flutter/test/material/refresh_indicator_test.dart +++ b/packages/flutter/test/material/refresh_indicator_test.dart @@ -721,7 +721,6 @@ void main() { refreshIndicatorColor = red; }); - await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0); await tester.pump(); expect(tester.widget(find.byType(RefreshProgressIndicator)).valueColor!.value, red.withOpacity(1.0)); }); diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index 2d6c8d0b116..a2783352b95 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -465,7 +465,7 @@ void main() { ), ); - await tester.drag(find.text('body'), const Offset(0.0, -1000.0)); + await tester.drag(find.byType(SingleChildScrollView), const Offset(0.0, -1000.0)); expect(didPressButton, isFalse); await tester.tap(find.text('X')); expect(didPressButton, isTrue); @@ -1392,24 +1392,28 @@ void main() { await tester.tap(drawerOpenButton); await tester.pumpAndSettle(); expect(true, scaffoldState.isDrawerOpen); - await tester.tap(endDrawerOpenButton); + await tester.tap(endDrawerOpenButton, warnIfMissed: false); // hits the modal barrier await tester.pumpAndSettle(); expect(false, scaffoldState.isDrawerOpen); await tester.tap(endDrawerOpenButton); await tester.pumpAndSettle(); expect(true, scaffoldState.isEndDrawerOpen); - await tester.tap(drawerOpenButton); + await tester.tap(drawerOpenButton, warnIfMissed: false); // hits the modal barrier await tester.pumpAndSettle(); expect(false, scaffoldState.isEndDrawerOpen); scaffoldState.openDrawer(); expect(true, scaffoldState.isDrawerOpen); - await tester.tap(drawerOpenButton); + await tester.tap(endDrawerOpenButton, warnIfMissed: false); // hits the modal barrier await tester.pumpAndSettle(); + expect(false, scaffoldState.isDrawerOpen); scaffoldState.openEndDrawer(); expect(true, scaffoldState.isEndDrawerOpen); + + scaffoldState.openDrawer(); + expect(true, scaffoldState.isDrawerOpen); }); testWidgets('Dual Drawer Opening', (WidgetTester tester) async { @@ -1441,7 +1445,7 @@ void main() { // not open the drawer. await tester.tap(find.byType(IconButton).first); await tester.pumpAndSettle(); - await tester.tap(find.byType(IconButton).last); + await tester.tap(find.byType(IconButton).last, warnIfMissed: false); // hits the modal barrier await tester.pumpAndSettle(); expect(find.text('endDrawer'), findsNothing); @@ -1456,7 +1460,7 @@ void main() { // Tapping on the end drawer and then on the drawer should close the // drawer and then reopen it. - await tester.tap(find.byType(IconButton).last); + await tester.tap(find.byType(IconButton).last, warnIfMissed: false); // hits the modal barrier await tester.pumpAndSettle(); await tester.tap(find.byType(IconButton).first); await tester.pumpAndSettle(); @@ -2099,6 +2103,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { scaffoldMessenger = ScaffoldMessenger.maybeOf(context); }, @@ -2106,7 +2111,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); } @@ -2136,6 +2140,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { ScaffoldMessenger.of(context); }, @@ -2143,7 +2148,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); } diff --git a/packages/flutter/test/material/snack_bar_test.dart b/packages/flutter/test/material/snack_bar_test.dart index a181eaa2cf7..c25b708275f 100644 --- a/packages/flutter/test/material/snack_bar_test.dart +++ b/packages/flutter/test/material/snack_bar_test.dart @@ -16,6 +16,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { Scaffold.of(context).showSnackBar(const SnackBar( content: Text(helloSnackBar), @@ -26,7 +27,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); } @@ -61,6 +61,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { ScaffoldMessenger.of(context).showSnackBar(const SnackBar( content: Text(helloSnackBar), @@ -71,7 +72,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); } @@ -106,6 +106,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { snackBarCount += 1; Scaffold.of(context).showSnackBar(SnackBar( @@ -117,7 +118,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); } @@ -181,6 +181,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { snackBarCount += 1; ScaffoldMessenger.of(context).showSnackBar(SnackBar( @@ -192,7 +193,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); } @@ -258,6 +258,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { snackBarCount += 1; lastController = Scaffold.of(context).showSnackBar(SnackBar( @@ -269,7 +270,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); } @@ -344,6 +344,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { snackBarCount += 1; lastController = ScaffoldMessenger.of(context).showSnackBar(SnackBar( @@ -355,7 +356,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); } @@ -428,6 +428,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { snackBarCount += 1; Scaffold.of(context).showSnackBar(SnackBar( @@ -439,7 +440,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); } @@ -473,6 +473,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { snackBarCount += 1; ScaffoldMessenger.of(context).showSnackBar(SnackBar( @@ -484,7 +485,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); } @@ -1592,25 +1592,25 @@ void main() { const String helloSnackBar = 'Hello SnackBar'; const Key tapTarget = Key('tap-target'); await tester.pumpWidget(MaterialApp( - home: Scaffold( - body: Builder( - builder: (BuildContext context) { - return GestureDetector( - onTap: () { - ScaffoldMessenger.of(context).showSnackBar(const SnackBar( - content: Text(helloSnackBar), - )); - }, - behavior: HitTestBehavior.opaque, - child: Container( - height: 100.0, - width: 100.0, - key: tapTarget, - ), - ); - } - ), + home: Scaffold( + body: Builder( + builder: (BuildContext context) { + return GestureDetector( + key: tapTarget, + onTap: () { + ScaffoldMessenger.of(context).showSnackBar(const SnackBar( + content: Text(helloSnackBar), + )); + }, + behavior: HitTestBehavior.opaque, + child: Container( + height: 100.0, + width: 100.0, + ), + ); + } ), + ), )); expect(find.text(helloSnackBar), findsNothing); await tester.tap(find.byKey(tapTarget)); @@ -1740,6 +1740,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: const Text('hello'), @@ -1753,7 +1754,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); }, @@ -1777,6 +1777,7 @@ void main() { body: Builder( builder: (BuildContext context) { return GestureDetector( + key: tapTarget, onTap: () { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: const Text('hello'), @@ -1797,7 +1798,6 @@ void main() { child: Container( height: 100.0, width: 100.0, - key: tapTarget, ), ); }, diff --git a/packages/flutter/test/material/tabs_test.dart b/packages/flutter/test/material/tabs_test.dart index 4c861cd8a93..4071ea42b22 100644 --- a/packages/flutter/test/material/tabs_test.dart +++ b/packages/flutter/test/material/tabs_test.dart @@ -2209,7 +2209,7 @@ void main() { // A fling in the TabBar or TabBarView, shouldn't do anything. - await tester.fling(find.byType(TabBar), const Offset(-100.0, 0.0), 5000.0); + await tester.fling(find.byType(TabBar), const Offset(-100.0, 0.0), 5000.0, warnIfMissed: false); await tester.pumpAndSettle(); await tester.fling(find.byType(TabBarView), const Offset(100.0, 0.0), 5000.0); diff --git a/packages/flutter/test/material/theme_test.dart b/packages/flutter/test/material/theme_test.dart index e13f177b56e..6e69d89c8b0 100644 --- a/packages/flutter/test/material/theme_test.dart +++ b/packages/flutter/test/material/theme_test.dart @@ -179,11 +179,9 @@ void main() { ); await tester.tap(find.text('SHOW')); - await tester.pump(const Duration(seconds: 1)); + await tester.pump(); // start animation + await tester.pump(const Duration(seconds: 1)); // end animation expect(Theme.of(tester.element(find.text('bottomSheet'))).brightness, equals(Brightness.light)); - - await tester.tap(find.text('bottomSheet')); // dismiss the bottom sheet - await tester.pump(const Duration(seconds: 1)); }); testWidgets('Dialog inherits shadowed app theme', (WidgetTester tester) async { diff --git a/packages/flutter/test/material/time_picker_test.dart b/packages/flutter/test/material/time_picker_test.dart index d60375ada5a..44077a380b1 100644 --- a/packages/flutter/test/material/time_picker_test.dart +++ b/packages/flutter/test/material/time_picker_test.dart @@ -745,8 +745,6 @@ void _tests() { textScaleFactor: 1.0, initialTime: const TimeOfDay(hour: 7, minute: 41), ); - await tester.tap(find.text('X')); - await tester.pumpAndSettle(); final double minutesDisplayHeight = tester.getSize(find.text('41')).height; final double amHeight = tester.getSize(find.text('AM')).height; @@ -761,8 +759,6 @@ void _tests() { textScaleFactor: 2.0, initialTime: const TimeOfDay(hour: 7, minute: 41), ); - await tester.tap(find.text('X')); - await tester.pumpAndSettle(); final double amHeight2x = tester.getSize(find.text('AM')).height; expect(tester.getSize(find.text('41')).height, equals(minutesDisplayHeight)); @@ -778,8 +774,6 @@ void _tests() { textScaleFactor: 3.0, initialTime: const TimeOfDay(hour: 7, minute: 41), ); - await tester.tap(find.text('X')); - await tester.pumpAndSettle(); expect(tester.getSize(find.text('41')).height, equals(minutesDisplayHeight)); expect(tester.getSize(find.text('AM')).height, equals(amHeight2x)); @@ -966,14 +960,14 @@ class PickerObserver extends NavigatorObserver { } Future mediaQueryBoilerplate( - WidgetTester tester, - bool alwaysUse24HourFormat, { - TimeOfDay initialTime = const TimeOfDay(hour: 7, minute: 0), - double textScaleFactor = 1.0, - TimePickerEntryMode entryMode = TimePickerEntryMode.dial, - String? helpText, - bool accessibleNavigation = false, - }) async { + WidgetTester tester, + bool alwaysUse24HourFormat, { + TimeOfDay initialTime = const TimeOfDay(hour: 7, minute: 0), + double textScaleFactor = 1.0, + TimePickerEntryMode entryMode = TimePickerEntryMode.dial, + String? helpText, + bool accessibleNavigation = false, +}) async { await tester.pumpWidget( Localizations( locale: const Locale('en', 'US'), @@ -1012,7 +1006,6 @@ Future mediaQueryBoilerplate( ), ), ); - await tester.tap(find.text('X')); await tester.pumpAndSettle(); } diff --git a/packages/flutter/test/widgets/absorb_pointer_test.dart b/packages/flutter/test/widgets/absorb_pointer_test.dart index 84e9f225b69..d03b6e102a2 100644 --- a/packages/flutter/test/widgets/absorb_pointer_test.dart +++ b/packages/flutter/test/widgets/absorb_pointer_test.dart @@ -26,7 +26,6 @@ void main() { ], ), ); - await tester.tap(find.byType(GestureDetector)); expect(tapped, true); }); diff --git a/packages/flutter/test/widgets/basic_test.dart b/packages/flutter/test/widgets/basic_test.dart index 32d75ca4b11..2c44c69dbc3 100644 --- a/packages/flutter/test/widgets/basic_test.dart +++ b/packages/flutter/test/widgets/basic_test.dart @@ -154,38 +154,38 @@ void main() { Offset offset = const Offset(0.4, 0.4); await tester.pumpWidget( - StatefulBuilder( - builder: (BuildContext context, StateSetter setState) { - return Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: Semantics( - explicitChildNodes: true, - child: FractionalTranslation( - key: fractionalTranslationKey, - translation: offset, - transformHitTests: true, - child: GestureDetector( - onTap: () { - setState(() { - offset = const Offset(0.8, 0.8); - }); - }, - child: SizedBox( - width: 100.0, - height: 100.0, - child: Text( - 'foo', - key: textKey, - ), + StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Semantics( + explicitChildNodes: true, + child: FractionalTranslation( + key: fractionalTranslationKey, + translation: offset, + transformHitTests: true, + child: GestureDetector( + onTap: () { + setState(() { + offset = const Offset(0.8, 0.8); + }); + }, + child: SizedBox( + width: 100.0, + height: 100.0, + child: Text( + 'foo', + key: textKey, ), ), ), ), ), - ); - }, - ) + ), + ); + }, + ) ); expect( @@ -198,7 +198,7 @@ void main() { ), ); - await tester.tap(find.byKey(fractionalTranslationKey)); + await tester.tap(find.byKey(fractionalTranslationKey), warnIfMissed: false); // RenderFractionalTranslation can't be hit await tester.pump(); expect( tester.getSemantics(find.byKey(textKey)).transform, diff --git a/packages/flutter/test/widgets/composited_transform_test.dart b/packages/flutter/test/widgets/composited_transform_test.dart index 2484ac4e4b3..118ecf23ed5 100644 --- a/packages/flutter/test/widgets/composited_transform_test.dart +++ b/packages/flutter/test/widgets/composited_transform_test.dart @@ -295,7 +295,7 @@ void main() { final RenderBox box2 = key2.currentContext!.findRenderObject()! as RenderBox; expect(box2.size, const Size(2.0, 2.0)); expect(tapped, isFalse); - await tester.tap(find.byKey(key3)); + await tester.tap(find.byKey(key3), warnIfMissed: false); // the container itself is transparent to hits expect(tapped, isTrue); }); } diff --git a/packages/flutter/test/widgets/container_test.dart b/packages/flutter/test/widgets/container_test.dart index 1c4c8791269..8f269ba387b 100644 --- a/packages/flutter/test/widgets/container_test.dart +++ b/packages/flutter/test/widgets/container_test.dart @@ -627,7 +627,7 @@ void main() { ), )); - await tester.tap(find.byType(Container)); + await tester.tap(find.byType(Container), warnIfMissed: false); expect(tapped, false); }); diff --git a/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart b/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart index f39d4e21119..88a6cb79dcc 100644 --- a/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart +++ b/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart @@ -151,7 +151,7 @@ void main() { await tester.drag(find.text('Item 1'), const Offset(0, -325)); await tester.pumpAndSettle(); expect(find.text('TapHere'), findsOneWidget); - await tester.tap(find.text('TapHere')); + await tester.tap(find.text('TapHere'), warnIfMissed: false); expect(taps, 1); expect(find.text('Item 1'), findsOneWidget); expect(find.text('Item 21'), findsOneWidget); @@ -203,7 +203,7 @@ void main() { await tester.fling(find.text('Item 1'), const Offset(0, -200), 2000); await tester.pumpAndSettle(); expect(find.text('TapHere'), findsOneWidget); - await tester.tap(find.text('TapHere')); + await tester.tap(find.text('TapHere'), warnIfMissed: false); expect(taps, 1); expect(find.text('Item 1'), findsNothing); expect(find.text('Item 21'), findsNothing); @@ -237,7 +237,7 @@ void main() { await tester.fling(find.text('Item 1'), const Offset(0, -200), 2000); await tester.pumpAndSettle(); expect(find.text('TapHere'), findsOneWidget); - await tester.tap(find.text('TapHere')); + await tester.tap(find.text('TapHere'), warnIfMissed: false); expect(taps, 1); expect(find.text('Item 1'), findsNothing); expect(find.text('Item 21'), findsNothing); @@ -246,7 +246,7 @@ void main() { await tester.fling(find.text('Item 70'), const Offset(0, 200), 2000); await tester.pumpAndSettle(); expect(find.text('TapHere'), findsOneWidget); - await tester.tap(find.text('TapHere')); + await tester.tap(find.text('TapHere'), warnIfMissed: false); expect(taps, 1); expect(find.text('Item 1'), findsOneWidget); expect(find.text('Item 21'), findsOneWidget); diff --git a/packages/flutter/test/widgets/draggable_test.dart b/packages/flutter/test/widgets/draggable_test.dart index 53b4abdc2ba..6c17c92845c 100644 --- a/packages/flutter/test/widgets/draggable_test.dart +++ b/packages/flutter/test/widgets/draggable_test.dart @@ -293,7 +293,7 @@ void main() { events.clear(); expect(events, isEmpty); - await tester.tap(find.text('Target')); + await tester.tap(find.text('Target'), warnIfMissed: false); // (inside IgnorePointer) expect(events, equals(['tap'])); events.clear(); @@ -325,7 +325,7 @@ void main() { expect(events, isEmpty); await tester.tap(find.text('Button')); - await tester.tap(find.text('Target')); + await tester.tap(find.text('Target'), warnIfMissed: false); // (inside IgnorePointer) await gesture.up(); await tester.pump(); expect(events, equals(['tap', 'tap', 'drop', 'details'])); diff --git a/packages/flutter/test/widgets/focus_manager_test.dart b/packages/flutter/test/widgets/focus_manager_test.dart index d24b195a3d7..2499236b68f 100644 --- a/packages/flutter/test/widgets/focus_manager_test.dart +++ b/packages/flutter/test/widgets/focus_manager_test.dart @@ -39,6 +39,7 @@ void main() { expect(parent.children.first, equals(child1)); expect(parent.children.last, equals(child2)); }); + testWidgets('Can remove children.', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusNode parent = FocusNode(); @@ -64,6 +65,7 @@ void main() { expect(child2.parent, isNull); expect(parent.children, isEmpty); }); + testWidgets('Geometry is transformed properly.', (WidgetTester tester) async { final FocusNode focusNode1 = FocusNode(debugLabel: 'Test Node 1'); final FocusNode focusNode2 = FocusNode(debugLabel: 'Test Node 2'); @@ -97,6 +99,7 @@ void main() { expect(focusNode1.offset, equals(const Offset(300.0, 8.0))); expect(focusNode2.offset, equals(const Offset(443.0, 194.5))); }); + testWidgets('descendantsAreFocusable disables focus for descendants.', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope = FocusScopeNode(debugLabel: 'Scope'); @@ -144,6 +147,7 @@ void main() { expect(scope.traversalDescendants.contains(child1), isFalse); expect(scope.traversalDescendants.contains(child2), isFalse); }); + testWidgets('implements debugFillProperties', (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); FocusNode( @@ -160,6 +164,7 @@ void main() { }); }); group(FocusScopeNode, () { + testWidgets('Can setFirstFocus on a scope with no manager.', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope = FocusScopeNode(debugLabel: 'Scope'); @@ -184,6 +189,7 @@ void main() { expect(scope.hasFocus, isFalse); expect(scope.focusedChild, equals(parent)); }); + testWidgets('Removing a node removes it from scope.', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope = FocusScopeNode(); @@ -208,6 +214,7 @@ void main() { expect(scope.hasFocus, isFalse); expect(scope.focusedChild, isNull); }); + testWidgets('Can add children to scope and focus', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope = FocusScopeNode(); @@ -247,6 +254,7 @@ void main() { expect(child2.hasFocus, isTrue); expect(child2.hasPrimaryFocus, isTrue); }); + testWidgets('Requesting focus before adding to tree results in a request after adding', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope = FocusScopeNode(); @@ -266,6 +274,7 @@ void main() { await tester.pump(); expect(child.hasPrimaryFocus, isTrue); // now attached and parented, so focus finally happened. }); + testWidgets('Autofocus works.', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope = FocusScopeNode(debugLabel: 'Scope'); @@ -302,6 +311,7 @@ void main() { expect(child2.hasFocus, isFalse); expect(child2.hasPrimaryFocus, isFalse); }); + testWidgets('Adding a focusedChild to a scope sets scope as focusedChild in parent scope', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope1 = FocusScopeNode(); @@ -333,6 +343,7 @@ void main() { expect(child2.hasFocus, isFalse); expect(child2.hasPrimaryFocus, isFalse); }); + testWidgets('Can move node with focus without losing focus', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope = FocusScopeNode(debugLabel: 'Scope'); @@ -369,6 +380,7 @@ void main() { expect(parent1.children.first, equals(child2)); expect(parent2.children.first, equals(child1)); }); + testWidgets('canRequestFocus affects children.', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope = FocusScopeNode(debugLabel: 'Scope', canRequestFocus: true); @@ -404,6 +416,7 @@ void main() { expect(scope.traversalDescendants.contains(child1), isFalse); expect(scope.traversalDescendants.contains(child2), isFalse); }); + testWidgets("skipTraversal doesn't affect children.", (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope = FocusScopeNode(debugLabel: 'Scope', skipTraversal: false); @@ -438,6 +451,7 @@ void main() { expect(scope.traversalDescendants.contains(child1), isTrue); expect(scope.traversalDescendants.contains(child2), isTrue); }); + testWidgets('Can move node between scopes and lose scope focus', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope1 = FocusScopeNode(debugLabel: 'scope1')..attach(context); @@ -475,6 +489,7 @@ void main() { expect(scope1.focusedChild, isNull); expect(parent2.children.contains(child1), isTrue); }); + testWidgets('ancestors and descendants are computed and recomputed properly', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope1 = FocusScopeNode(debugLabel: 'scope1'); @@ -510,6 +525,7 @@ void main() { expect(child4.ancestors, equals([parent2, scope2, child2, parent1, scope1, tester.binding.focusManager.rootScope])); expect(tester.binding.focusManager.rootScope.descendants, equals([child1, child3, child4, parent2, scope2, child2, parent1, scope1])); }); + testWidgets('Can move focus between scopes and keep focus', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope1 = FocusScopeNode(); @@ -567,6 +583,7 @@ void main() { expect(scope1.focusedChild, equals(child1)); expect(scope2.focusedChild, equals(child4)); }); + testWidgets('Unfocus with disposition previouslyFocusedChild works properly', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope1 = FocusScopeNode(debugLabel: 'scope1')..attach(context); @@ -647,6 +664,7 @@ void main() { expect(child1.hasPrimaryFocus, isFalse); expect(child3.hasPrimaryFocus, isTrue); }); + testWidgets('Unfocus with disposition scope works properly', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope1 = FocusScopeNode(debugLabel: 'scope1')..attach(context); @@ -731,6 +749,7 @@ void main() { expect(child3.hasPrimaryFocus, isFalse); expect(FocusManager.instance.rootScope.hasPrimaryFocus, isTrue); }); + testWidgets('Unfocus works properly when some nodes are unfocusable', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope1 = FocusScopeNode(debugLabel: 'scope1')..attach(context); @@ -796,6 +815,7 @@ void main() { expect(child1.hasPrimaryFocus, isFalse); expect(child2.hasPrimaryFocus, isFalse); }); + testWidgets('Requesting focus on a scope works properly when some focusedChild nodes are unfocusable', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope1 = FocusScopeNode(debugLabel: 'scope1')..attach(context); @@ -849,6 +869,7 @@ void main() { expect(scope2.focusedChild, equals(child4)); expect(child4.hasPrimaryFocus, isTrue); }); + testWidgets('Key handling bubbles up and terminates when handled.', (WidgetTester tester) async { final Set receivedAnEvent = {}; final Set shouldHandle = {}; @@ -912,6 +933,7 @@ void main() { // receive it. expect(receivedAnEvent, isEmpty); }); + testWidgets('Initial highlight mode guesses correctly.', (WidgetTester tester) async { FocusManager.instance.highlightStrategy = FocusHighlightStrategy.automatic; switch (defaultTargetPlatform) { @@ -927,6 +949,7 @@ void main() { break; } }, variant: TargetPlatformVariant.all()); + testWidgets('Mouse events change initial focus highlight mode on mobile.', (WidgetTester tester) async { expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.touch)); RendererBinding.instance!.initMouseTracker(); // Clear out the mouse state. @@ -935,6 +958,7 @@ void main() { await gesture.moveTo(Offset.zero); expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.traditional)); }, variant: TargetPlatformVariant.mobile()); + testWidgets('Mouse events change initial focus highlight mode on desktop.', (WidgetTester tester) async { expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.traditional)); RendererBinding.instance!.initMouseTracker(); // Clear out the mouse state. @@ -943,10 +967,12 @@ void main() { await gesture.moveTo(Offset.zero); expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.traditional)); }, variant: TargetPlatformVariant.desktop()); + testWidgets('Keyboard events change initial focus highlight mode.', (WidgetTester tester) async { await tester.sendKeyEvent(LogicalKeyboardKey.enter); expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.traditional)); }, variant: TargetPlatformVariant.all()); + testWidgets('Events change focus highlight mode.', (WidgetTester tester) async { await setupWidget(tester); int callCount = 0; @@ -955,7 +981,6 @@ void main() { lastMode = mode; callCount++; } - FocusManager.instance.addHighlightModeListener(handleModeChange); addTearDown(() => FocusManager.instance.removeHighlightModeListener(handleModeChange)); expect(callCount, equals(0)); @@ -966,7 +991,7 @@ void main() { expect(callCount, equals(1)); expect(lastMode, FocusHighlightMode.traditional); expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.traditional)); - await tester.tap(find.byType(Container)); + await tester.tap(find.byType(Container), warnIfMissed: false); expect(callCount, equals(2)); expect(lastMode, FocusHighlightMode.touch); expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.touch)); @@ -976,7 +1001,7 @@ void main() { expect(callCount, equals(3)); expect(lastMode, FocusHighlightMode.traditional); expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.traditional)); - await tester.tap(find.byType(Container)); + await tester.tap(find.byType(Container), warnIfMissed: false); expect(callCount, equals(4)); expect(lastMode, FocusHighlightMode.touch); expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.touch)); @@ -989,6 +1014,7 @@ void main() { expect(lastMode, FocusHighlightMode.touch); expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.touch)); }); + testWidgets('implements debugFillProperties', (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); FocusScopeNode( @@ -1003,6 +1029,7 @@ void main() { 'hasPrimaryFocus: false' ]); }); + testWidgets('debugDescribeFocusTree produces correct output', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode scope1 = FocusScopeNode(debugLabel: 'Scope 1'); @@ -1073,6 +1100,7 @@ void main() { )); }); }); + testWidgets("Doesn't lose focused child when reparenting if the nearestScope doesn't change.", (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode parent1 = FocusScopeNode(debugLabel: 'parent1'); @@ -1098,6 +1126,7 @@ void main() { await tester.pump(); expect(parent1.focusedChild, equals(child2)); }); + testWidgets('Ancestors get notified exactly as often as needed if focused child changes focus.', (WidgetTester tester) async { bool topFocus = false; bool parent1Focus = false; @@ -1228,6 +1257,7 @@ void main() { expect(parent2Notify, equals(0)); expect(child2Notify, equals(0)); }); + testWidgets('Focus changes notify listeners.', (WidgetTester tester) async { final BuildContext context = await setupWidget(tester); final FocusScopeNode parent1 = FocusScopeNode(debugLabel: 'parent1'); @@ -1271,6 +1301,7 @@ void main() { tester.binding.focusManager.removeListener(handleFocusChange); }); + testWidgets('FocusManager notifies listeners when a widget loses focus because it was removed.', (WidgetTester tester) async { final FocusNode nodeA = FocusNode(debugLabel: 'a'); final FocusNode nodeB = FocusNode(debugLabel: 'b'); diff --git a/packages/flutter/test/widgets/heroes_test.dart b/packages/flutter/test/widgets/heroes_test.dart index 22d4a6d5f5f..136910331f2 100644 --- a/packages/flutter/test/widgets/heroes_test.dart +++ b/packages/flutter/test/widgets/heroes_test.dart @@ -537,18 +537,18 @@ Future main() async { navigator.pushNamed('/next'); expect(log, isEmpty); - await tester.tap(find.text('foo', skipOffstage: false)); + await tester.tap(find.text('foo', skipOffstage: false), warnIfMissed: false); expect(log, isEmpty); await tester.pump(const Duration(milliseconds: 10)); - await tester.tap(find.text('foo', skipOffstage: false)); + await tester.tap(find.text('foo', skipOffstage: false), warnIfMissed: false); expect(log, isEmpty); - await tester.tap(find.text('bar', skipOffstage: false)); + await tester.tap(find.text('bar', skipOffstage: false), warnIfMissed: false); expect(log, isEmpty); await tester.pump(const Duration(milliseconds: 10)); expect(find.text('foo'), findsNothing); - await tester.tap(find.text('bar', skipOffstage: false)); + await tester.tap(find.text('bar', skipOffstage: false), warnIfMissed: false); expect(log, isEmpty); await tester.pump(const Duration(seconds: 1)); @@ -976,7 +976,7 @@ Future main() async { // Scroll the target upwards by 25 pixels. The Hero flight's Y coordinate // will be redirected from 100 to 75. - await tester.drag(find.byKey(routeContainerKey), const Offset(0.0, -25.0)); + await tester.drag(find.byKey(routeContainerKey), const Offset(0.0, -25.0), warnIfMissed: false); // the container itself wouldn't be hit await tester.pump(); await tester.pump(const Duration(milliseconds: 10)); final double yAt110ms = tester.getTopLeft(find.byKey(routeHeroKey)).dy; @@ -1052,7 +1052,7 @@ Future main() async { expect(yAt100ms, lessThan(200.0)); expect(yAt100ms, greaterThan(100.0)); - await tester.drag(find.byKey(routeContainerKey), const Offset(0.0, -400.0)); + await tester.drag(find.byKey(routeContainerKey), const Offset(0.0, -400.0), warnIfMissed: false); // the container itself wouldn't be hit await tester.pump(); await tester.pump(const Duration(milliseconds: 10)); expect(find.byKey(routeContainerKey), findsNothing); // Scrolled off the top diff --git a/packages/flutter/test/widgets/keep_alive_test.dart b/packages/flutter/test/widgets/keep_alive_test.dart index bcc4f6d1f2e..0d945f585fa 100644 --- a/packages/flutter/test/widgets/keep_alive_test.dart +++ b/packages/flutter/test/widgets/keep_alive_test.dart @@ -258,6 +258,7 @@ void main() { ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ size: Size(800.0, 600.0)\n' + ' │ behavior: opaque\n' ' │ gestures: vertical scroll\n' ' │\n' ' └─child: RenderPointerListener#00000\n' @@ -406,6 +407,7 @@ void main() { ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ size: Size(800.0, 600.0)\n' + ' │ behavior: opaque\n' ' │ gestures: vertical scroll\n' ' │\n' ' └─child: RenderPointerListener#00000\n' diff --git a/packages/flutter/test/widgets/modal_barrier_test.dart b/packages/flutter/test/widgets/modal_barrier_test.dart index ef2b2bb3648..d6035ba82d4 100644 --- a/packages/flutter/test/widgets/modal_barrier_test.dart +++ b/packages/flutter/test/widgets/modal_barrier_test.dart @@ -54,7 +54,7 @@ void main() { ); await tester.pumpWidget(subject); - await tester.tap(find.text('target')); + await tester.tap(find.text('target'), warnIfMissed: false); await tester.pumpWidget(subject); expect(tapped, isFalse, reason: 'because the tap is not prevented by ModalBarrier'); @@ -181,7 +181,7 @@ void main() { ); await tester.pumpWidget(subject); - await tester.tap(find.text('target')); + await tester.tap(find.text('target'), warnIfMissed: false); await tester.pumpWidget(subject); } finally { SystemChannels.platform.setMockMethodCallHandler(null); diff --git a/packages/flutter/test/widgets/navigator_test.dart b/packages/flutter/test/widgets/navigator_test.dart index 1f36249ee1e..22faf4797ac 100644 --- a/packages/flutter/test/widgets/navigator_test.dart +++ b/packages/flutter/test/widgets/navigator_test.dart @@ -279,7 +279,7 @@ void main() { expect(log, isEmpty); await tester.tap(find.text('left')); expect(log, equals(['left'])); - await tester.tap(find.text('right')); + await tester.tap(find.text('right'), warnIfMissed: false); expect(log, equals(['left'])); }); diff --git a/packages/flutter/test/widgets/nested_scroll_view_test.dart b/packages/flutter/test/widgets/nested_scroll_view_test.dart index 35a8aa283d3..c55a3077397 100644 --- a/packages/flutter/test/widgets/nested_scroll_view_test.dart +++ b/packages/flutter/test/widgets/nested_scroll_view_test.dart @@ -2139,7 +2139,7 @@ void main() { // Tap after releasing the overscroll to trigger secondary inner ballistic // scroll activity with 0 velocity. - await tester.tap(find.text('Item 49')); + await tester.tap(find.text('Item 49'), warnIfMissed: false); await tester.pumpAndSettle(); // If handled correctly, the ballistic scroll activity should finish diff --git a/packages/flutter/test/widgets/overlay_test.dart b/packages/flutter/test/widgets/overlay_test.dart index bbbb9f0f7e3..025a0b6fd92 100644 --- a/packages/flutter/test/widgets/overlay_test.dart +++ b/packages/flutter/test/widgets/overlay_test.dart @@ -923,7 +923,7 @@ void main() { ); expect(bottomTapCount, 0); - await tester.tap(find.byKey(overlayKey)); + await tester.tap(find.byKey(overlayKey), warnIfMissed: false); // gesture detector is translucent; no hit is registered between it and the render view expect(bottomTapCount, 1); overlayKey.currentState!.insert(OverlayEntry( @@ -938,7 +938,7 @@ void main() { // Bottom is offstage and does not receive tap events. expect(find.byType(GestureDetector), findsNothing); expect(find.byType(GestureDetector, skipOffstage: false), findsOneWidget); - await tester.tap(find.byKey(overlayKey)); + await tester.tap(find.byKey(overlayKey), warnIfMissed: false); // gesture detector is translucent; no hit is registered between it and the render view expect(bottomTapCount, 1); int topTapCount = 0; @@ -956,7 +956,7 @@ void main() { await tester.pump(); expect(topTapCount, 0); - await tester.tap(find.byKey(overlayKey)); + await tester.tap(find.byKey(overlayKey), warnIfMissed: false); // gesture detector is translucent; no hit is registered between it and the render view expect(topTapCount, 1); expect(bottomTapCount, 1); }); diff --git a/packages/flutter/test/widgets/range_maintaining_scroll_physics_test.dart b/packages/flutter/test/widgets/range_maintaining_scroll_physics_test.dart index dabc3764335..4c3229412e3 100644 --- a/packages/flutter/test/widgets/range_maintaining_scroll_physics_test.dart +++ b/packages/flutter/test/widgets/range_maintaining_scroll_physics_test.dart @@ -256,7 +256,7 @@ void main() { // - scroll extents have changed // - position does not change at the same time // - old position is out of old range AND new range - await tester.drag(find.byType(Placeholder), const Offset(0.0, 100.0), touchSlopY: 0.0); + await tester.drag(find.byType(Placeholder), const Offset(0.0, 100.0), touchSlopY: 0.0, warnIfMissed: false); // it'll hit the scrollable await tester.pump(); final Rect oldPosition = tester.getRect(find.byType(Placeholder)); await tester.pumpWidget(build(220.0)); diff --git a/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart b/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart index 56a2b84c334..3b13bee440b 100644 --- a/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart +++ b/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart @@ -96,7 +96,7 @@ void main() { expect(tapped, equals([])); await tester.tap(find.text('1')); expect(tapped, equals([1])); - await tester.tap(find.text('3')); + await tester.tap(find.text('3'), warnIfMissed: false); expect(tapped, equals([1])); // the center of the third item is off-screen so it shouldn't get hit }); diff --git a/packages/flutter/test/widgets/scrollable_restoration_test.dart b/packages/flutter/test/widgets/scrollable_restoration_test.dart index a69e8cd0898..5b564f2fd56 100644 --- a/packages/flutter/test/widgets/scrollable_restoration_test.dart +++ b/packages/flutter/test/widgets/scrollable_restoration_test.dart @@ -399,7 +399,7 @@ void main() { expect(find.text('Tile 0'), findsOneWidget); expect(find.text('Tile 10'), findsNothing); - await tester.drag(find.byType(ListView), const Offset(0, -500)); + await tester.drag(find.byType(NestedScrollView), const Offset(0, -500)); await tester.pump(); expect(tester.renderObject(find.byType(SliverAppBar)).geometry!.paintExtent, 56); @@ -413,7 +413,7 @@ void main() { expect(find.text('Tile 10'), findsOneWidget); final TestRestorationData data = await tester.getRestorationData(); - await tester.drag(find.byType(ListView), const Offset(0, 600)); + await tester.drag(find.byType(NestedScrollView), const Offset(0, 600)); await tester.pump(); expect(tester.renderObject(find.byType(SliverAppBar)).geometry!.paintExtent, 150); diff --git a/packages/flutter/test/widgets/scrollable_test.dart b/packages/flutter/test/widgets/scrollable_test.dart index 51dc053c4e0..316f672f41d 100644 --- a/packages/flutter/test/widgets/scrollable_test.dart +++ b/packages/flutter/test/widgets/scrollable_test.dart @@ -93,7 +93,7 @@ void resetScrollOffset(WidgetTester tester) { void main() { testWidgets('Flings on different platforms', (WidgetTester tester) async { await pumpTest(tester, TargetPlatform.android); - await tester.fling(find.byType(Viewport), const Offset(0.0, -dragOffset), 1000.0); + await tester.fling(find.byType(Scrollable), const Offset(0.0, -dragOffset), 1000.0); expect(getScrollOffset(tester), dragOffset); await tester.pump(); // trigger fling expect(getScrollOffset(tester), dragOffset); @@ -103,7 +103,7 @@ void main() { resetScrollOffset(tester); await pumpTest(tester, TargetPlatform.iOS); - await tester.fling(find.byType(Viewport), const Offset(0.0, -dragOffset), 1000.0); + await tester.fling(find.byType(Scrollable), const Offset(0.0, -dragOffset), 1000.0); // Scroll starts ease into the scroll on iOS. expect(getScrollOffset(tester), moreOrLessEquals(197.16666666666669)); await tester.pump(); // trigger fling @@ -114,7 +114,7 @@ void main() { resetScrollOffset(tester); await pumpTest(tester, TargetPlatform.macOS); - await tester.fling(find.byType(Viewport), const Offset(0.0, -dragOffset), 1000.0); + await tester.fling(find.byType(Scrollable), const Offset(0.0, -dragOffset), 1000.0); // Scroll starts ease into the scroll on iOS. expect(getScrollOffset(tester), moreOrLessEquals(197.16666666666669)); await tester.pump(); // trigger fling @@ -128,7 +128,7 @@ void main() { testWidgets('Holding scroll', (WidgetTester tester) async { await pumpTest(tester, debugDefaultTargetPlatformOverride); - await tester.drag(find.byType(Viewport), const Offset(0.0, 200.0), touchSlopY: 0.0); + await tester.drag(find.byType(Scrollable), const Offset(0.0, 200.0), touchSlopY: 0.0); expect(getScrollOffset(tester), -200.0); await tester.pump(); // trigger ballistic await tester.pump(const Duration(milliseconds: 10)); @@ -136,7 +136,7 @@ void main() { expect(getScrollOffset(tester), lessThan(0.0)); final double heldPosition = getScrollOffset(tester); // Hold and let go while in overscroll. - final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Viewport))); + final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Scrollable), warnIfMissed: true)); expect(await tester.pumpAndSettle(), 1); expect(getScrollOffset(tester), heldPosition); await gesture.up(); @@ -147,11 +147,11 @@ void main() { testWidgets('Repeated flings builds momentum', (WidgetTester tester) async { await pumpTest(tester, debugDefaultTargetPlatformOverride); - await tester.fling(find.byType(Viewport), const Offset(0.0, -dragOffset), 1000.0); + await tester.fling(find.byType(Scrollable), const Offset(0.0, -dragOffset), 1000.0); await tester.pump(); // trigger fling await tester.pump(const Duration(milliseconds: 10)); // Repeat the exact same motion. - await tester.fling(find.byType(Viewport), const Offset(0.0, -dragOffset), 1000.0); + await tester.fling(find.byType(Scrollable), const Offset(0.0, -dragOffset), 1000.0); await tester.pump(); // On iOS, the velocity will be larger than the velocity of the last fling by a // non-trivial amount. @@ -160,11 +160,11 @@ void main() { testWidgets('Repeated flings do not build momentum on Android', (WidgetTester tester) async { await pumpTest(tester, TargetPlatform.android); - await tester.fling(find.byType(Viewport), const Offset(0.0, -dragOffset), 1000.0); + await tester.fling(find.byType(Scrollable), const Offset(0.0, -dragOffset), 1000.0); await tester.pump(); // trigger fling await tester.pump(const Duration(milliseconds: 10)); // Repeat the exact same motion. - await tester.fling(find.byType(Viewport), const Offset(0.0, -dragOffset), 1000.0); + await tester.fling(find.byType(Scrollable), const Offset(0.0, -dragOffset), 1000.0); await tester.pump(); // On Android, there is no momentum build. The final velocity is the same as the // velocity of the last fling. @@ -173,11 +173,11 @@ void main() { testWidgets('No iOS/macOS momentum build with flings in opposite directions', (WidgetTester tester) async { await pumpTest(tester, debugDefaultTargetPlatformOverride); - await tester.fling(find.byType(Viewport), const Offset(0.0, -dragOffset), 1000.0); + await tester.fling(find.byType(Scrollable), const Offset(0.0, -dragOffset), 1000.0); await tester.pump(); // trigger fling await tester.pump(const Duration(milliseconds: 10)); // Repeat the exact same motion in the opposite direction. - await tester.fling(find.byType(Viewport), const Offset(0.0, dragOffset), 1000.0); + await tester.fling(find.byType(Scrollable), const Offset(0.0, dragOffset), 1000.0); await tester.pump(); // The only applied velocity to the scrollable is the second fling that was in the // opposite direction. @@ -186,11 +186,11 @@ void main() { testWidgets('No iOS/macOS momentum kept on hold gestures', (WidgetTester tester) async { await pumpTest(tester, debugDefaultTargetPlatformOverride); - await tester.fling(find.byType(Viewport), const Offset(0.0, -dragOffset), 1000.0); + await tester.fling(find.byType(Scrollable), const Offset(0.0, -dragOffset), 1000.0); await tester.pump(); // trigger fling await tester.pump(const Duration(milliseconds: 10)); expect(getScrollVelocity(tester), greaterThan(0.0)); - final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Viewport))); + final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Scrollable), warnIfMissed: true)); await tester.pump(const Duration(milliseconds: 40)); await gesture.up(); // After a hold longer than 2 frames, previous velocity is lost. @@ -199,7 +199,7 @@ void main() { testWidgets('Drags creeping unaffected on Android', (WidgetTester tester) async { await pumpTest(tester, TargetPlatform.android); - final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Viewport))); + final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Scrollable), warnIfMissed: true)); await gesture.moveBy(const Offset(0.0, -0.5)); expect(getScrollOffset(tester), 0.5); await gesture.moveBy(const Offset(0.0, -0.5), timeStamp: const Duration(milliseconds: 10)); @@ -210,7 +210,7 @@ void main() { testWidgets('Drags creeping must break threshold on iOS/macOS', (WidgetTester tester) async { await pumpTest(tester, debugDefaultTargetPlatformOverride); - final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Viewport))); + final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Scrollable), warnIfMissed: true)); await gesture.moveBy(const Offset(0.0, -0.5)); expect(getScrollOffset(tester), 0.0); await gesture.moveBy(const Offset(0.0, -0.5), timeStamp: const Duration(milliseconds: 10)); @@ -230,7 +230,7 @@ void main() { testWidgets('Big drag over threshold magnitude preserved on iOS/macOS', (WidgetTester tester) async { await pumpTest(tester, debugDefaultTargetPlatformOverride); - final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Viewport))); + final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Scrollable), warnIfMissed: true)); await gesture.moveBy(const Offset(0.0, -30.0)); // No offset lost from threshold. expect(getScrollOffset(tester), 30.0); @@ -238,7 +238,7 @@ void main() { testWidgets('Slow threshold breaks are attenuated on iOS/macOS', (WidgetTester tester) async { await pumpTest(tester, debugDefaultTargetPlatformOverride); - final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Viewport))); + final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Scrollable), warnIfMissed: true)); // This is a typical 'hesitant' iOS scroll start. await gesture.moveBy(const Offset(0.0, -10.0)); expect(getScrollOffset(tester), moreOrLessEquals(1.1666666666666667)); @@ -249,7 +249,7 @@ void main() { testWidgets('Small continuing motion preserved on iOS/macOS', (WidgetTester tester) async { await pumpTest(tester, debugDefaultTargetPlatformOverride); - final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Viewport))); + final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Scrollable), warnIfMissed: true)); await gesture.moveBy(const Offset(0.0, -30.0)); // Break threshold. expect(getScrollOffset(tester), 30.0); await gesture.moveBy(const Offset(0.0, -0.5), timeStamp: const Duration(milliseconds: 20)); @@ -262,7 +262,7 @@ void main() { testWidgets('Motion stop resets threshold on iOS/macOS', (WidgetTester tester) async { await pumpTest(tester, debugDefaultTargetPlatformOverride); - final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Viewport))); + final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Scrollable), warnIfMissed: true)); await gesture.moveBy(const Offset(0.0, -30.0)); // Break threshold. expect(getScrollOffset(tester), 30.0); await gesture.moveBy(const Offset(0.0, -0.5), timeStamp: const Duration(milliseconds: 20)); @@ -334,7 +334,7 @@ void main() { lastUserScrollingDirection = controller.position.userScrollDirection; }); - await tester.drag(find.byType(Viewport), const Offset(0.0, -20.0), touchSlopY: 0.0); + await tester.drag(find.byType(Scrollable), const Offset(0.0, -20.0), touchSlopY: 0.0); expect(lastUserScrollingDirection, ScrollDirection.reverse); @@ -346,7 +346,7 @@ void main() { expect(lastUserScrollingDirection, ScrollDirection.reverse); - await tester.drag(find.byType(Viewport), const Offset(0.0, 20.0), touchSlopY: 0.0); + await tester.drag(find.byType(Scrollable), const Offset(0.0, 20.0), touchSlopY: 0.0); expect(lastUserScrollingDirection, ScrollDirection.forward); @@ -434,7 +434,7 @@ void main() { expect(renderIgnorePointer.ignoring, false); // Starts ignoring when the drag is recognized. - await tester.fling(find.byType(Viewport), const Offset(0, -100), 1000); + await tester.fling(find.byType(Scrollable), const Offset(0, -100), 1000); expect(renderIgnorePointer.ignoring, true); await tester.pump(); diff --git a/packages/flutter/test/widgets/semantics_debugger_test.dart b/packages/flutter/test/widgets/semantics_debugger_test.dart index 26e6d16495d..62b159b4cea 100644 --- a/packages/flutter/test/widgets/semantics_debugger_test.dart +++ b/packages/flutter/test/widgets/semantics_debugger_test.dart @@ -178,11 +178,11 @@ void main() { ), ); - await tester.tap(find.text('TOP')); + await tester.tap(find.text('TOP'), warnIfMissed: false); // hitting the debugger expect(log, equals(['top'])); log.clear(); - await tester.tap(find.text('BOTTOM')); + await tester.tap(find.text('BOTTOM'), warnIfMissed: false); // hitting the debugger expect(log, equals(['bottom'])); log.clear(); }); @@ -218,11 +218,11 @@ void main() { ), ); - await tester.tap(find.text('TOP')); + await tester.tap(find.text('TOP'), warnIfMissed: false); // hitting the debugger expect(log, equals(['top'])); log.clear(); - await tester.tap(find.text('BOTTOM')); + await tester.tap(find.text('BOTTOM'), warnIfMissed: false); // hitting the debugger expect(log, equals([])); log.clear(); }); @@ -249,22 +249,22 @@ void main() { expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); - await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 200.0); + await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 200.0, warnIfMissed: false); // hitting the debugger); await tester.pump(); expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(-480.0)); - await tester.fling(find.byType(ListView), const Offset(200.0, 0.0), 200.0); + await tester.fling(find.byType(ListView), const Offset(200.0, 0.0), 200.0, warnIfMissed: false); // hitting the debugger); await tester.pump(); expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(-480.0)); - await tester.fling(find.byType(ListView), const Offset(-200.0, 0.0), 200.0); + await tester.fling(find.byType(ListView), const Offset(-200.0, 0.0), 200.0, warnIfMissed: false); // hitting the debugger); await tester.pump(); expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(-480.0)); - await tester.fling(find.byType(ListView), const Offset(0.0, 200.0), 200.0); + await tester.fling(find.byType(ListView), const Offset(0.0, 200.0), 200.0, warnIfMissed: false); // hitting the debugger); await tester.pump(); expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); @@ -288,7 +288,7 @@ void main() { ), ); - await tester.longPress(find.text('target')); + await tester.longPress(find.text('target'), warnIfMissed: false); // hitting the debugger expect(didLongPress, isTrue); }); @@ -324,7 +324,7 @@ void main() { // it won't trigger. The actual distance moved doesn't matter since this is // interpreted as a gesture by the semantics debugger and sent to the widget // as a semantic action that always moves by 10% of the complete track. - await tester.fling(find.byType(Slider), const Offset(-100.0, 0.0), 2000.0); + await tester.fling(find.byType(Slider), const Offset(-100.0, 0.0), 2000.0, warnIfMissed: false); // hitting the debugger expect(value, equals(0.70)); }); @@ -360,12 +360,12 @@ void main() { ), ); - await tester.tap(find.byKey(keyTop)); + await tester.tap(find.byKey(keyTop), warnIfMissed: false); // hitting the debugger expect(valueTop, isTrue); valueTop = false; expect(valueTop, isFalse); - await tester.tap(find.byKey(keyBottom)); + await tester.tap(find.byKey(keyBottom), warnIfMissed: false); // hitting the debugger expect(valueTop, isFalse); }); diff --git a/packages/flutter/test/widgets/sliver_visibility_test.dart b/packages/flutter/test/widgets/sliver_visibility_test.dart index 9a6def53681..aaf559e7244 100644 --- a/packages/flutter/test/widgets/sliver_visibility_test.dart +++ b/packages/flutter/test/widgets/sliver_visibility_test.dart @@ -260,7 +260,7 @@ void main() { expect(renderSliver.constraints.crossAxisExtent, 800.0); expect(semantics.nodesWith(label: 'a true'), hasLength(1)); expect(log, ['created new state']); - await tester.tap(find.byKey(anchor)); + await tester.tap(find.byKey(anchor), warnIfMissed: false); expect(log, ['created new state']); log.clear(); @@ -282,7 +282,7 @@ void main() { expect(renderSliver.constraints.crossAxisExtent, 800.0); expect(semantics.nodesWith(label: 'a true'), hasLength(0)); expect(log, []); - await tester.tap(find.byKey(anchor)); + await tester.tap(find.byKey(anchor), warnIfMissed: false); expect(log, []); log.clear(); diff --git a/packages/flutter/test/widgets/slivers_test.dart b/packages/flutter/test/widgets/slivers_test.dart index af223c40dba..9db3ee12579 100644 --- a/packages/flutter/test/widgets/slivers_test.dart +++ b/packages/flutter/test/widgets/slivers_test.dart @@ -778,7 +778,7 @@ void main() { ) )); expect(semantics.nodesWith(label: 'a'), hasLength(1)); - await tester.tap(find.byType(GestureDetector)); + await tester.tap(find.byType(GestureDetector), warnIfMissed: false); expect(events, equals([])); }); @@ -822,7 +822,7 @@ void main() { ) )); expect(semantics.nodesWith(label: 'a'), hasLength(0)); - await tester.tap(find.byType(GestureDetector)); + await tester.tap(find.byType(GestureDetector), warnIfMissed: false); expect(events, equals([])); }); diff --git a/packages/flutter/test/widgets/stack_test.dart b/packages/flutter/test/widgets/stack_test.dart index 4731d692909..9c5d9ee110c 100644 --- a/packages/flutter/test/widgets/stack_test.dart +++ b/packages/flutter/test/widgets/stack_test.dart @@ -409,7 +409,7 @@ void main() { ), ); - await tester.tap(find.byType(IndexedStack)); + await tester.tap(find.byType(IndexedStack), warnIfMissed: false); final RenderBox box = tester.renderObject(find.byType(IndexedStack)); expect(box.size, equals(const Size(200.0, 200.0))); expect(tapped, isNull); diff --git a/packages/flutter/test/widgets/visibility_test.dart b/packages/flutter/test/widgets/visibility_test.dart index cda26e75773..34b7e348d04 100644 --- a/packages/flutter/test/widgets/visibility_test.dart +++ b/packages/flutter/test/widgets/visibility_test.dart @@ -84,7 +84,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), const Size(800.0, 600.0)); expect(semantics, expectedSemanticsWhenAbsent); expect(log, []); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, []); log.clear(); @@ -100,7 +100,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), Size.zero); expect(semantics, expectedSemanticsWhenAbsent); expect(log, []); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, []); log.clear(); @@ -117,7 +117,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), const Size(800.0, 600.0)); expect(semantics, expectedSemanticsWhenAbsent); expect(log, []); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, []); log.clear(); @@ -221,7 +221,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); expect(semantics, expectedSemanticsWhenPresent); expect(log, ['created new state']); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, ['created new state']); log.clear(); @@ -241,7 +241,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); expect(semantics, expectedSemanticsWhenAbsent); expect(log, []); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, []); log.clear(); @@ -261,7 +261,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), Size.zero); expect(semantics, expectedSemanticsWhenAbsent); expect(log, ['created new state']); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, ['created new state']); log.clear(); @@ -280,7 +280,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), Size.zero); expect(semantics, expectedSemanticsWhenAbsent); expect(log, ['created new state']); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, ['created new state']); log.clear(); @@ -300,7 +300,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); expect(semantics, expectedSemanticsWhenPresent); expect(log, []); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, ['tap']); log.clear(); @@ -319,7 +319,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), Size.zero); expect(semantics, expectedSemanticsWhenAbsent); expect(log, []); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, []); log.clear(); @@ -356,7 +356,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), Size.zero); expect(semantics, expectedSemanticsWhenAbsent); expect(log, []); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, []); log.clear(); @@ -374,7 +374,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), Size.zero); expect(semantics, expectedSemanticsWhenAbsent); expect(log, []); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, []); log.clear(); @@ -407,7 +407,7 @@ void main() { expect(tester.getSize(find.byType(Visibility)), Size.zero); expect(semantics, expectedSemanticsWhenAbsent); expect(log, []); - await tester.tap(find.byType(Visibility)); + await tester.tap(find.byType(Visibility), warnIfMissed: false); expect(log, []); log.clear(); diff --git a/packages/flutter/test/widgets/widget_inspector_test.dart b/packages/flutter/test/widgets/widget_inspector_test.dart index d8fe8956dcd..bee1e1ae9be 100644 --- a/packages/flutter/test/widgets/widget_inspector_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_test.dart @@ -314,7 +314,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ); expect(getInspectorState().selection.current, isNull); - await tester.tap(find.text('TOP')); + await tester.tap(find.text('TOP'), warnIfMissed: false); await tester.pump(); // Tap intercepted by the inspector expect(log, equals([])); @@ -338,7 +338,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // We are now back in select mode so tapping the bottom button will have // not trigger a click but will cause it to be selected. - await tester.tap(find.text('BOTTOM')); + await tester.tap(find.text('BOTTOM'), warnIfMissed: false); expect(log, equals([])); log.clear(); expect(paragraphText(getInspectorState().selection.current as RenderParagraph), equals('BOTTOM')); @@ -364,7 +364,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ); - await tester.tap(find.byType(Transform)); + await tester.tap(find.byType(Transform), warnIfMissed: false); expect(true, isTrue); // Expect that we reach here without crashing. }); @@ -400,19 +400,19 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ); expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); - await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 200.0); + await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 200.0, warnIfMissed: false); await tester.pump(); // Fling does nothing as are in inspect mode. expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); - await tester.fling(find.byType(ListView), const Offset(200.0, 0.0), 200.0); + await tester.fling(find.byType(ListView), const Offset(200.0, 0.0), 200.0, warnIfMissed: false); await tester.pump(); // Fling still does nothing as are in inspect mode. expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); - await tester.tap(find.byType(ListView)); + await tester.tap(find.byType(ListView), warnIfMissed: false); await tester.pump(); expect(getInspectorState().selection.current, isNotNull); @@ -447,7 +447,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ); - await tester.longPress(find.text('target')); + await tester.longPress(find.text('target'), warnIfMissed: false); // The inspector will swallow the long press. expect(didLongPress, isFalse); }); @@ -499,7 +499,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ); - await tester.longPress(find.byKey(clickTarget)); + await tester.longPress(find.byKey(clickTarget), warnIfMissed: false); // State type is private, hence using dynamic. final dynamic inspectorState = inspectorKey.currentState; // The object with width 95.0 wins over the object with width 94.0 because @@ -549,7 +549,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ); - await tester.tap(find.byKey(childKey)); + await tester.tap(find.byKey(childKey), warnIfMissed: false); await tester.pump(); await expectLater( @@ -619,11 +619,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // The selection is static, so it may be initialized from previous tests. selection.clear(); - await tester.tap(find.text('Child 1')); + await tester.tap(find.text('Child 1'), warnIfMissed: false); await tester.pump(); expect(paragraphText(selection.current! as RenderParagraph), equals('Child 1')); - await tester.tap(find.text('Child 2')); + await tester.tap(find.text('Child 2'), warnIfMissed: false); await tester.pump(); expect(paragraphText(selection.current! as RenderParagraph), equals('Child 2')); }); diff --git a/packages/flutter_test/lib/flutter_test.dart b/packages/flutter_test/lib/flutter_test.dart index d05840d5de6..fbeb6f13608 100644 --- a/packages/flutter_test/lib/flutter_test.dart +++ b/packages/flutter_test/lib/flutter_test.dart @@ -42,6 +42,15 @@ /// root of the project. /// /// If no configuration file is located, the test will be executed like normal. +/// +/// See also: +/// +/// * [WidgetController.hitTestWarningShouldBeFatal], which can be set +/// in a `flutter_test_config.dart` file to turn warnings printed by +/// [WidgetTester.tap] and similar APIs into fatal errors. +/// * [debugCheckIntrinsicSizes], which can be set in a +/// `flutter_test_config.dart` file to enable deeper [RenderBox] +/// tests of the intrinsic APIs automatically while laying out widgets. library flutter_test; export 'dart:async' show Future; diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index 3e76c6c8f96..cafaf87b98a 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -212,7 +212,11 @@ abstract class TestWidgetsFlutterBinding extends BindingBase /// change the behavior of [debugPrint]. For example, /// [AutomatedTestWidgetsFlutterBinding] uses it to make [debugPrint] /// synchronous, disabling its normal throttling behavior. - @protected + /// + /// It is also used by some other parts of the test framework (e.g. + /// [WidgetTester.printToConsole]) to ensure that messages from the + /// test framework are displayed to the developer rather than logged + /// by whatever code is overriding [debugPrint]. DebugPrintCallback get debugPrintOverride => debugPrint; /// The value to set [debugDisableShadows] to while tests are running. diff --git a/packages/flutter_test/lib/src/controller.dart b/packages/flutter_test/lib/src/controller.dart index bbe00d66feb..ba3339a092b 100644 --- a/packages/flutter_test/lib/src/controller.dart +++ b/packages/flutter_test/lib/src/controller.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:clock/clock.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; @@ -251,10 +252,23 @@ abstract class WidgetController { /// Dispatch a pointer down / pointer up sequence at the center of /// the given widget, assuming it is exposed. /// - /// If the center of the widget is not exposed, this might send events to - /// another object. - Future tap(Finder finder, {int? pointer, int buttons = kPrimaryButton}) { - return tapAt(getCenter(finder), pointer: pointer, buttons: buttons); + /// {@template flutter.flutter_test.WidgetController.tap.warnIfMissed} + /// The `warnIfMissed` argument, if true (the default), causes a warning to be + /// displayed on the console if the specified [Finder] indicates a widget and + /// location that, were a pointer event to be sent to that location, would not + /// actually send any events to the widget (e.g. because the widget is + /// obscured, or the location is off-screen, or the widget is transparent to + /// pointer events). + /// + /// Set the argument to false to silence that warning if you intend to not + /// actually hit the specified element. + /// {@endtemplate} + /// + /// For example, a test that verifies that tapping a disabled button does not + /// trigger the button would set `warnIfMissed` to false, because the button + /// would ignore the tap. + Future tap(Finder finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) { + return tapAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'tap'), pointer: pointer, buttons: buttons); } /// Dispatch a pointer down / pointer up sequence at the given location. @@ -268,11 +282,19 @@ abstract class WidgetController { /// Dispatch a pointer down at the center of the given widget, assuming it is /// exposed. /// - /// If the center of the widget is not exposed, this might send events to - /// another object. - Future press(Finder finder, {int? pointer, int buttons = kPrimaryButton}) { + /// {@macro flutter.flutter_test.WidgetController.tap.warnIfMissed} + /// + /// The return value is a [TestGesture] object that can be used to continue the + /// gesture (e.g. moving the pointer or releasing it). + /// + /// See also: + /// + /// * [tap], which presses and releases a pointer at the given location. + /// * [longPress], which presses and releases a pointer with a gap in + /// between long enough to trigger the long-press gesture. + Future press(Finder finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) { return TestAsyncUtils.guard(() { - return startGesture(getCenter(finder), pointer: pointer, buttons: buttons); + return startGesture(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'press'), pointer: pointer, buttons: buttons); }); } @@ -280,10 +302,16 @@ abstract class WidgetController { /// [kLongPressTimeout] + [kPressTimeout] between the two events) at the /// center of the given widget, assuming it is exposed. /// - /// If the center of the widget is not exposed, this might send events to - /// another object. - Future longPress(Finder finder, {int? pointer, int buttons = kPrimaryButton}) { - return longPressAt(getCenter(finder), pointer: pointer, buttons: buttons); + /// {@macro flutter.flutter_test.WidgetController.tap.warnIfMissed} + /// + /// For example, consider a widget that, when long-pressed, shows an overlay + /// that obscures the original widget. A test for that widget might first + /// long-press that widget with `warnIfMissed` at its default value true, then + /// later verify that long-pressing the same location (using the same finder) + /// has no effect (since the widget is now obscured), setting `warnIfMissed` + /// to false on that second call. + Future longPress(Finder finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) { + return longPressAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'longPress'), pointer: pointer, buttons: buttons); } /// Dispatch a pointer down / pointer up sequence at the given location with @@ -299,8 +327,7 @@ abstract class WidgetController { /// Attempts a fling gesture starting from the center of the given /// widget, moving the given distance, reaching the given speed. /// - /// If the middle of the widget is not exposed, this might send - /// events to another object. + /// {@macro flutter.flutter_test.WidgetController.tap.warnIfMissed} /// /// {@template flutter.flutter_test.WidgetController.fling} /// This can pump frames. @@ -342,9 +369,10 @@ abstract class WidgetController { Duration frameInterval = const Duration(milliseconds: 16), Offset initialOffset = Offset.zero, Duration initialOffsetDelay = const Duration(seconds: 1), + bool warnIfMissed = true, }) { return flingFrom( - getCenter(finder), + getCenter(finder, warnIfMissed: warnIfMissed, callee: 'fling'), offset, speed, pointer: pointer, @@ -467,8 +495,7 @@ abstract class WidgetController { /// Attempts to drag the given widget by the given offset, by /// starting a drag in the middle of the widget. /// - /// If the middle of the widget is not exposed, this might send - /// events to another object. + /// {@macro flutter.flutter_test.WidgetController.tap.warnIfMissed} /// /// If you want the drag to end with a speed so that the gesture recognition /// system identifies the gesture as a fling, consider using [fling] instead. @@ -500,9 +527,10 @@ abstract class WidgetController { int buttons = kPrimaryButton, double touchSlopX = kDragSlopDefault, double touchSlopY = kDragSlopDefault, + bool warnIfMissed = true, }) { return dragFrom( - getCenter(finder), + getCenter(finder, warnIfMissed: warnIfMissed, callee: 'drag'), offset, pointer: pointer, buttons: buttons, @@ -606,8 +634,7 @@ abstract class WidgetController { /// Attempts to drag the given widget by the given offset in the `duration` /// time, starting in the middle of the widget. /// - /// If the middle of the widget is not exposed, this might send - /// events to another object. + /// {@macro flutter.flutter_test.WidgetController.tap.warnIfMissed} /// /// This is the timed version of [drag]. This may or may not result in a /// [fling] or ballistic animation, depending on the speed from @@ -629,9 +656,10 @@ abstract class WidgetController { int? pointer, int buttons = kPrimaryButton, double frequency = 60.0, + bool warnIfMissed = true, }) { return timedDragFrom( - getCenter(finder), + getCenter(finder, warnIfMissed: warnIfMissed, callee: 'timedDrag'), offset, duration, pointer: pointer, @@ -779,41 +807,157 @@ abstract class WidgetController { }); } + /// Calls [debugPrint] with the given message. + /// + /// This is overridden by the WidgetTester subclass to use the test binding's + /// [TestWidgetsFlutterBinding.debugPrintOverride], so that it appears on the + /// console even if the test is logging output from the application. + @protected + void printToConsole(String message) { + debugPrint(message); + } + // GEOMETRY /// Returns the point at the center of the given widget. - Offset getCenter(Finder finder) { - return _getElementPoint(finder, (Size size) => size.center(Offset.zero)); + /// + /// {@template flutter.flutter_test.WidgetController.getCenter.warnIfMissed} + /// If `warnIfMissed` is true (the default is false), then the returned + /// coordinate is checked to see if a hit test at the returned location would + /// actually include the specified element in the [HitTestResult], and if not, + /// a warning is printed to the console. + /// + /// The `callee` argument is used to identify the method that should be + /// referenced in messages regarding `warnIfMissed`. It can be ignored unless + /// this method is being called from another that is forwarding its own + /// `warnIfMissed` parameter (see e.g. the implementation of [tap]). + /// {@endtemplate} + Offset getCenter(Finder finder, { bool warnIfMissed = false, String callee = 'getCenter' }) { + return _getElementPoint(finder, (Size size) => size.center(Offset.zero), warnIfMissed: warnIfMissed, callee: callee); } /// Returns the point at the top left of the given widget. - Offset getTopLeft(Finder finder) { - return _getElementPoint(finder, (Size size) => Offset.zero); + /// + /// {@macro flutter.flutter_test.WidgetController.getCenter.warnIfMissed} + Offset getTopLeft(Finder finder, { bool warnIfMissed = false, String callee = 'getTopLeft' }) { + return _getElementPoint(finder, (Size size) => Offset.zero, warnIfMissed: warnIfMissed, callee: callee); } /// Returns the point at the top right of the given widget. This /// point is not inside the object's hit test area. - Offset getTopRight(Finder finder) { - return _getElementPoint(finder, (Size size) => size.topRight(Offset.zero)); + /// + /// {@macro flutter.flutter_test.WidgetController.getCenter.warnIfMissed} + Offset getTopRight(Finder finder, { bool warnIfMissed = false, String callee = 'getTopRight' }) { + return _getElementPoint(finder, (Size size) => size.topRight(Offset.zero), warnIfMissed: warnIfMissed, callee: callee); } /// Returns the point at the bottom left of the given widget. This /// point is not inside the object's hit test area. - Offset getBottomLeft(Finder finder) { - return _getElementPoint(finder, (Size size) => size.bottomLeft(Offset.zero)); + /// + /// {@macro flutter.flutter_test.WidgetController.getCenter.warnIfMissed} + Offset getBottomLeft(Finder finder, { bool warnIfMissed = false, String callee = 'getBottomLeft' }) { + return _getElementPoint(finder, (Size size) => size.bottomLeft(Offset.zero), warnIfMissed: warnIfMissed, callee: callee); } /// Returns the point at the bottom right of the given widget. This /// point is not inside the object's hit test area. - Offset getBottomRight(Finder finder) { - return _getElementPoint(finder, (Size size) => size.bottomRight(Offset.zero)); + /// + /// {@macro flutter.flutter_test.WidgetController.getCenter.warnIfMissed} + Offset getBottomRight(Finder finder, { bool warnIfMissed = false, String callee = 'getBottomRight' }) { + return _getElementPoint(finder, (Size size) => size.bottomRight(Offset.zero), warnIfMissed: warnIfMissed, callee: callee); } - Offset _getElementPoint(Finder finder, Offset sizeToPoint(Size size)) { + /// Whether warnings relating to hit tests not hitting their mark should be + /// fatal (cause the test to fail). + /// + /// Some methods, e.g. [tap], have an argument `warnIfMissed` which causes a + /// warning to be displayed if the specified [Finder] indicates a widget and + /// location that, were a pointer event to be sent to that location, would not + /// actually send any events to the widget (e.g. because the widget is + /// obscured, or the location is off-screen, or the widget is transparent to + /// pointer events). + /// + /// This warning was added in 2021. In ordinary operation this warning is + /// non-fatal since making it fatal would be a significantly breaking change + /// for anyone who already has tests relying on the ability to target events + /// using finders where the events wouldn't reach the widgets specified by the + /// finders in question. + /// + /// However, doing this is usually unintentional. To make the warning fatal, + /// thus failing any tests where it occurs, this property can be set to true. + /// + /// Typically this is done using a `flutter_test_config.dart` file, as described + /// in the documentation for the [flutter_test] library. + static bool hitTestWarningShouldBeFatal = false; + + Offset _getElementPoint(Finder finder, Offset sizeToPoint(Size size), { required bool warnIfMissed, required String callee }) { TestAsyncUtils.guardSync(); - final Element element = finder.evaluate().single; + final Iterable elements = finder.evaluate(); + if (elements.isEmpty) { + throw FlutterError('The finder "$finder" (used in a call to "$callee()") could not find any matching widgets.'); + } + if (elements.length > 1) { + throw FlutterError('The finder "$finder" (used in a call to "$callee()") ambiguously found multiple matching widgets. The "$callee()" method needs a single target.'); + } + final Element element = elements.single; + final RenderObject? renderObject = element.renderObject; + if (renderObject == null) { + throw FlutterError( + 'The finder "$finder" (used in a call to "$callee()") found an element, but it does not have a corresponding render object. ' + 'Maybe the element has not yet been rendered?' + ); + } + if (renderObject is! RenderBox) { + throw FlutterError( + 'The finder "$finder" (used in a call to "$callee()") found an element whose corresponding render object is not a RenderBox (it is a ${renderObject.runtimeType}: "$renderObject"). ' + 'Unfortunately "$callee()" only supports targetting widgets that correspond to RenderBox objects in the rendering.' + ); + } final RenderBox box = element.renderObject! as RenderBox; - return box.localToGlobal(sizeToPoint(box.size)); + final Offset location = box.localToGlobal(sizeToPoint(box.size)); + if (warnIfMissed) { + final HitTestResult result = HitTestResult(); + binding.hitTest(result, location); + bool found = false; + for (final HitTestEntry entry in result.path) { + if (entry.target == box) { + found = true; + break; + } + } + if (!found) { + bool outOfBounds = false; + if (binding.renderView != null && binding.renderView.size != null) { + outOfBounds = !(Offset.zero & binding.renderView.size).contains(location); + } + if (hitTestWarningShouldBeFatal) { + throw FlutterError.fromParts([ + ErrorSummary('Finder specifies a widget that would not receive pointer events.'), + ErrorDescription('A call to $callee() with finder "$finder" derived an Offset ($location) that would not hit test on the specified widget.'), + ErrorHint('Maybe the widget is actually off-screen, or another widget is obscuring it, or the widget cannot receive pointer events.'), + if (outOfBounds) + ErrorHint('Indeed, $location is outside the bounds of the root of the render tree, ${binding.renderView.size}.'), + box.toDiagnosticsNode(name: 'The finder corresponds to this RenderBox', style: DiagnosticsTreeStyle.singleLine), + ErrorDescription('The hit test result at that offset is: $result'), + ErrorDescription('If you expected this target not to be able to receive pointer events, pass "warnIfMissed: false" to "$callee()".'), + ErrorDescription('To make this error into a non-fatal warning, set WidgetController.hitTestWarningShouldBeFatal to false.'), + ]); + } + printToConsole( + '\n' + 'Warning: A call to $callee() with finder "$finder" derived an Offset ($location) that would not hit test on the specified widget.\n' + 'Maybe the widget is actually off-screen, or another widget is obscuring it, or the widget cannot receive pointer events.\n' + '${outOfBounds ? "Indeed, $location is outside the bounds of the root of the render tree, ${binding.renderView.size}.\n" : ""}' + 'The finder corresponds to this RenderBox: $box\n' + 'The hit test result at that offset is: $result\n' + '${StackTrace.current}' + 'To silence this warning, pass "warnIfMissed: false" to "$callee()".\n' + 'To make this warning fatal, set WidgetController.hitTestWarningShouldBeFatal to true.\n' + '' + ); + } + } + return location; } /// Returns the size of the given widget. This is only valid once diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index d9e58c3346a..5063463f0e9 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -797,7 +797,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker orElse: () => null, ); if (innerTargetElement == null) { - debugPrint('No widgets found at ${binding.globalToLocal(event.position)}.'); + printToConsole('No widgets found at ${binding.globalToLocal(event.position)}.'); return; } final List candidates = []; @@ -810,7 +810,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker int numberOfWithTexts = 0; int numberOfTypes = 0; int totalNumber = 0; - debugPrint('Some possible finders for the widgets at ${binding.globalToLocal(event.position)}:'); + printToConsole('Some possible finders for the widgets at ${binding.globalToLocal(event.position)}:'); for (final Element element in candidates) { if (totalNumber > 13) // an arbitrary number of finders that feels useful without being overwhelming break; @@ -820,7 +820,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker if (widget is Tooltip) { final Iterable matches = find.byTooltip(widget.message).evaluate(); if (matches.length == 1) { - debugPrint(" find.byTooltip('${widget.message}')"); + printToConsole(" find.byTooltip('${widget.message}')"); continue; } } @@ -832,7 +832,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker final Iterable matches = find.text(text).evaluate(); descendantText = widget.data; if (matches.length == 1) { - debugPrint(" find.text('$text')"); + printToConsole(" find.text('$text')"); continue; } } @@ -850,7 +850,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker if (keyLabel != null) { final Iterable matches = find.byKey(key).evaluate(); if (matches.length == 1) { - debugPrint(' find.byKey($keyLabel)'); + printToConsole(' find.byKey($keyLabel)'); continue; } } @@ -860,7 +860,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker if (numberOfTypes < 5) { final Iterable matches = find.byType(widget.runtimeType).evaluate(); if (matches.length == 1) { - debugPrint(' find.byType(${widget.runtimeType})'); + printToConsole(' find.byType(${widget.runtimeType})'); numberOfTypes += 1; continue; } @@ -869,7 +869,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker if (descendantText != null && numberOfWithTexts < 5) { final Iterable matches = find.widgetWithText(widget.runtimeType, descendantText).evaluate(); if (matches.length == 1) { - debugPrint(" find.widgetWithText(${widget.runtimeType}, '$descendantText')"); + printToConsole(" find.widgetWithText(${widget.runtimeType}, '$descendantText')"); numberOfWithTexts += 1; continue; } @@ -879,7 +879,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker if (!_isPrivate(element.runtimeType)) { final Iterable matches = find.byElementType(element.runtimeType).evaluate(); if (matches.length == 1) { - debugPrint(' find.byElementType(${element.runtimeType})'); + printToConsole(' find.byElementType(${element.runtimeType})'); continue; } } @@ -887,7 +887,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker totalNumber -= 1; // if we got here, we didn't actually find something to say about it } if (totalNumber == 0) - debugPrint(' '); + printToConsole(' '); } } @@ -1061,6 +1061,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker await tap(backButton); }); } + + @override + void printToConsole(String message) { + binding.debugPrintOverride(message); + } } typedef _TickerDisposeCallback = void Function(_TestTicker ticker);