gesture.dart 2.78 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 'find.dart';
6

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

12
  /// Deserializes this command from the value generated by [serialize].
13
  Tap.deserialize(super.json, super.finderFactory) : super.deserialize();
14 15

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

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

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

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

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

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

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

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

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

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

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

76 77 78 79 80 81
  /// 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.
82
  final double alignment;
83

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

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