diff --git a/dev/integration_tests/flutter_gallery/test/live_smoketest.dart b/dev/integration_tests/flutter_gallery/test/live_smoketest.dart index 44afcc9b0d..cbc7fe9a60 100644 --- a/dev/integration_tests/flutter_gallery/test/live_smoketest.dart +++ b/dev/integration_tests/flutter_gallery/test/live_smoketest.dart @@ -11,7 +11,7 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; -import 'package:flutter/gestures.dart' show kPrimaryButton; +import 'package:flutter/gestures.dart' show PointerDeviceKind, kPrimaryButton; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; @@ -137,13 +137,18 @@ class _LiveWidgetController extends LiveWidgetController { return finder; } - @override - Future tap(FinderBase finder, { int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true }) async { - await super.tap(await _waitForElement(finder), pointer: pointer, buttons: buttons, warnIfMissed: warnIfMissed); - } - Future scrollIntoView(FinderBase finder, {required double alignment}) async { final FinderBase target = await _waitForElement(finder); await Scrollable.ensureVisible(target.evaluate().single, duration: const Duration(milliseconds: 100), alignment: alignment); } + + @override + Future tap(FinderBase finder, { + int? pointer, + int buttons = kPrimaryButton, + bool warnIfMissed = true, + PointerDeviceKind kind = PointerDeviceKind.touch, + }) async { + await super.tap(await _waitForElement(finder), pointer: pointer, buttons: buttons, warnIfMissed: warnIfMissed, kind: kind); + } } diff --git a/packages/flutter/test/material/slider_test.dart b/packages/flutter/test/material/slider_test.dart index 58e260595c..e2193290ee 100644 --- a/packages/flutter/test/material/slider_test.dart +++ b/packages/flutter/test/material/slider_test.dart @@ -3432,7 +3432,7 @@ void main() { await gesture.up(); await tester.pumpAndSettle(); expect(value, isNot(equals(0.5))); - // The slider does not have have focus after the value is changed. + // The slider does not have focus after the value is changed. expect(focusNode.hasFocus, false); }); @@ -3618,8 +3618,8 @@ void main() { ); }, variant: TargetPlatformVariant.desktop()); - testWidgetsWithLeakTracking('Value indicator disappears after adjusting the slider', (WidgetTester tester) async { - // This is a regression test for https://github.com/flutter/flutter/issues/123313. + // Regression test for https://github.com/flutter/flutter/issues/123313, which only occurs on desktop platforms. + testWidgetsWithLeakTracking('Value indicator disappears after adjusting the slider on desktop', (WidgetTester tester) async { final ThemeData theme = ThemeData(useMaterial3: true); const double currentValue = 0.5; await tester.pumpWidget(MaterialApp( @@ -3630,7 +3630,7 @@ void main() { value: currentValue, divisions: 5, label: currentValue.toStringAsFixed(1), - onChanged: (double value) {}, + onChanged: (_) {}, ), ), ), @@ -3647,8 +3647,8 @@ void main() { final Offset sliderCenter = tester.getCenter(find.byType(Slider)); final Offset tapLocation = Offset(sliderCenter.dx + 50, sliderCenter.dy); - // Tap the slider to bring up the value indicator. - await tester.tapAt(tapLocation); + // Tap the slider by mouse to bring up the value indicator. + await tester.tapAt(tapLocation, kind: PointerDeviceKind.mouse); await tester.pumpAndSettle(); // Value indicator is visible. @@ -3666,7 +3666,7 @@ void main() { valueIndicatorBox, isNot(paints..scale()..path(color: theme.colorScheme.primary)), ); - }); + }, variant: TargetPlatformVariant.desktop()); testWidgetsWithLeakTracking('Value indicator remains when Slider is in focus on desktop', (WidgetTester tester) async { double value = 0.5; diff --git a/packages/flutter_test/lib/src/controller.dart b/packages/flutter_test/lib/src/controller.dart index bd5ae46d1d..2bc735d007 100644 --- a/packages/flutter_test/lib/src/controller.dart +++ b/packages/flutter_test/lib/src/controller.dart @@ -987,14 +987,25 @@ abstract class WidgetController { /// 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(finders.FinderBase finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) { - return tapAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'tap'), pointer: pointer, buttons: buttons); + Future tap( + finders.FinderBase finder, { + int? pointer, + int buttons = kPrimaryButton, + bool warnIfMissed = true, + PointerDeviceKind kind = PointerDeviceKind.touch, + }) { + return tapAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'tap'), pointer: pointer, buttons: buttons, kind: kind); } /// Dispatch a pointer down / pointer up sequence at the given location. - Future tapAt(Offset location, {int? pointer, int buttons = kPrimaryButton}) { + Future tapAt( + Offset location, { + int? pointer, + int buttons = kPrimaryButton, + PointerDeviceKind kind = PointerDeviceKind.touch, + }) { return TestAsyncUtils.guard(() async { - final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons); + final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons, kind: kind); await gesture.up(); }); } @@ -1012,9 +1023,20 @@ abstract class WidgetController { /// * [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(finders.FinderBase finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) { + Future press( + finders.FinderBase finder, { + int? pointer, + int buttons = kPrimaryButton, + bool warnIfMissed = true, + PointerDeviceKind kind = PointerDeviceKind.touch, + }) { return TestAsyncUtils.guard(() { - return startGesture(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'press'), pointer: pointer, buttons: buttons); + return startGesture( + getCenter(finder, warnIfMissed: warnIfMissed, callee: 'press'), + pointer: pointer, + buttons: buttons, + kind: kind, + ); }); } @@ -1030,15 +1052,31 @@ abstract class WidgetController { /// 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(finders.FinderBase finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) { - return longPressAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'longPress'), pointer: pointer, buttons: buttons); + Future longPress( + finders.FinderBase finder, { + int? pointer, + int buttons = kPrimaryButton, + bool warnIfMissed = true, + PointerDeviceKind kind = PointerDeviceKind.touch, + }) { + return longPressAt( + getCenter(finder, warnIfMissed: warnIfMissed, callee: 'longPress'), + pointer: pointer, + buttons: buttons, + kind: kind, + ); } /// Dispatch a pointer down / pointer up sequence at the given location with /// a delay of [kLongPressTimeout] + [kPressTimeout] between the two events. - Future longPressAt(Offset location, {int? pointer, int buttons = kPrimaryButton}) { + Future longPressAt( + Offset location, { + int? pointer, + int buttons = kPrimaryButton, + PointerDeviceKind kind = PointerDeviceKind.touch, + }) { return TestAsyncUtils.guard(() async { - final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons); + final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons, kind: kind); await pump(kLongPressTimeout + kPressTimeout); await gesture.up(); });