mock_events.dart 1.39 KB
Newer Older
1
import 'dart:ui' as ui;
2

3
import 'package:flutter/gestures.dart';
4

5
export 'dart:ui' show Point;
6

7 8 9 10 11
class TestPointer {
  TestPointer([ this.pointer = 1 ]);

  int pointer;
  bool isDown = false;
12
  ui.Point location;
13

14
  PointerInputEvent down(ui.Point newLocation, { double timeStamp: 0.0 }) {
15 16 17
    assert(!isDown);
    isDown = true;
    location = newLocation;
18
    return new PointerInputEvent(
19 20 21
      type: 'pointerdown',
      pointer: pointer,
      x: location.x,
22 23
      y: location.y,
      timeStamp: timeStamp
24 25 26
    );
  }

27
  PointerInputEvent move(ui.Point newLocation, { double timeStamp: 0.0 }) {
28
    assert(isDown);
29
    ui.Offset delta = newLocation - location;
30
    location = newLocation;
31
    return new PointerInputEvent(
32 33 34 35 36
      type: 'pointermove',
      pointer: pointer,
      x: newLocation.x,
      y: newLocation.y,
      dx: delta.dx,
37 38
      dy: delta.dy,
      timeStamp: timeStamp
39 40 41
    );
  }

42
  PointerInputEvent up({ double timeStamp: 0.0 }) {
43 44
    assert(isDown);
    isDown = false;
45
    return new PointerInputEvent(
46 47 48
      type: 'pointerup',
      pointer: pointer,
      x: location.x,
49 50
      y: location.y,
      timeStamp: timeStamp
51 52 53
    );
  }

54
  PointerInputEvent cancel({ double timeStamp: 0.0 }) {
55 56
    assert(isDown);
    isDown = false;
57
    return new PointerInputEvent(
58 59 60
      type: 'pointercancel',
      pointer: pointer,
      x: location.x,
61 62
      y: location.y,
      timeStamp: timeStamp
63 64 65 66
    );
  }

}