gesture.dart 3.12 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'deserialization_factory.dart';
6
import 'find.dart';
7

8
/// A Flutter Driver command that taps on a target widget located by [finder].
9
class Tap extends CommandWithTarget {
10
  /// Creates a tap command to tap on a widget located by [finder].
11
  Tap(SerializableFinder finder, { Duration? timeout }) : super(finder, timeout: timeout);
12

13
  /// Deserializes this command from the value generated by [serialize].
14
  Tap.deserialize(Map<String, String> json, DeserializeFinderFactory finderFactory) : super.deserialize(json, finderFactory);
15 16

  @override
17
  String get kind => 'tap';
18 19
}

20
/// A Flutter Driver command that commands the driver to perform a scrolling action.
21
class Scroll extends CommandWithTarget {
22 23
  /// Creates a scroll command that will attempt to scroll a scrollable view by
  /// dragging a widget located by the given [finder].
24
  Scroll(
25
    SerializableFinder finder,
26 27 28
    this.dx,
    this.dy,
    this.duration,
29
    this.frequency, {
30
    Duration? timeout,
31
  }) : super(finder, timeout: timeout);
32

33
  /// Deserializes this command from the value generated by [serialize].
34
  Scroll.deserialize(Map<String, String> json, DeserializeFinderFactory finderFactory)
35 36 37 38
    : dx = double.parse(json['dx']!),
      dy = double.parse(json['dy']!),
      duration = Duration(microseconds: int.parse(json['duration']!)),
      frequency = int.parse(json['frequency']!),
39
      super.deserialize(json, finderFactory);
40 41 42 43 44 45 46

  /// Delta X offset per move event.
  final double dx;

  /// Delta Y offset per move event.
  final double dy;

47
  /// The duration of the scrolling action.
48 49 50 51 52
  final Duration duration;

  /// The frequency in Hz of the generated move events.
  final int frequency;

53
  @override
54
  String get kind => 'scroll';
55

56
  @override
pq's avatar
pq committed
57
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
58 59 60 61
    'dx': '$dx',
    'dy': '$dy',
    'duration': '${duration.inMicroseconds}',
    'frequency': '$frequency',
62 63 64
  });
}

65 66
/// A Flutter Driver command that commands the driver to ensure that the element
/// represented by [finder] has been scrolled completely into view.
67
class ScrollIntoView extends CommandWithTarget {
68 69
  /// Creates this command given a [finder] used to locate the widget to be
  /// scrolled into view.
70
  ScrollIntoView(SerializableFinder finder, { this.alignment = 0.0, Duration? timeout }) : super(finder, timeout: timeout);
71

72
  /// Deserializes this command from the value generated by [serialize].
73
  ScrollIntoView.deserialize(Map<String, String> json, DeserializeFinderFactory finderFactory)
74
    : alignment = double.parse(json['alignment']!),
75
      super.deserialize(json, finderFactory);
76

77 78 79 80 81 82
  /// How the widget should be aligned.
  ///
  /// This value is passed to [Scrollable.ensureVisible] as the value of its
  /// argument of the same name.
  ///
  /// Defaults to 0.0.
83
  final double alignment;
84

85
  @override
86
  String get kind => 'scrollIntoView';
87

88
  @override
89 90 91
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'alignment': '$alignment',
  });
92
}