Unverified Commit aa4b4d35 authored by Ming Lyu (CareF)'s avatar Ming Lyu (CareF) Committed by GitHub

LiveTestWidgetsFlutterBinding support for non-touch event (#61872)

parent 3577da53
......@@ -1468,6 +1468,11 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
/// Events dispatched by [TestGesture] are not affected by this.
HitTestDispatcher deviceEventDispatcher;
/// Dispatch an event to a hit test result's path.
///
/// Apart from forwarding the event to [GestureBinding.dispatchEvent],
/// This also paint all events that's down on the screen.
@override
void dispatchEvent(
PointerEvent event,
......@@ -1476,20 +1481,19 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
}) {
switch (source) {
case TestBindingEventSource.test:
if (!renderView._pointers.containsKey(event.pointer)) {
assert(event.down || event is PointerAddedEvent);
if (event.down) {
renderView._pointers[event.pointer] = _LiveTestPointerRecord(
event.pointer,
event.position,
);
}
} else {
if (renderView._pointers.containsKey(event.pointer)) {
renderView._pointers[event.pointer].position = event.position;
if (!event.down)
renderView._pointers[event.pointer].decay = _kPointerDecay;
_handleViewNeedsPaint();
} else if (event.down) {
assert(event is PointerDownEvent);
renderView._pointers[event.pointer] = _LiveTestPointerRecord(
event.pointer,
event.position,
);
_handleViewNeedsPaint();
}
_handleViewNeedsPaint();
super.dispatchEvent(event, hitTestResult, source: source);
break;
case TestBindingEventSource.device:
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -16,4 +18,15 @@ void main() {
// starts with a PointerAddedEvent.
await gesture.addPointer();
});
testWidgets('Input PointerHoverEvent', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: Text('Test')));
await tester.pump();
final TestGesture gesture = await tester.createGesture(
kind: PointerDeviceKind.mouse);
final Offset location = tester.getCenter(find.text('Test'));
// for mouse input without a down event, moveTo generates a hover event
await gesture.moveTo(location);
await gesture.removePointer();
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment