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

import 'find.dart';
import 'message.dart';

/// A Flutter Driver command that reads the text from a given element.
class GetText extends CommandWithTarget {
  /// [finder] looks for an element that contains a piece of text.
11
  GetText(super.finder, { super.timeout });
12 13

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

  @override
17
  String get kind => 'get_text';
18 19 20 21 22
}

/// The result of the [GetText] command.
class GetTextResult extends Result {
  /// Creates a result with the given [text].
23
  const GetTextResult(this.text);
24 25 26 27 28 29

  /// The text extracted by the [GetText] command.
  final String text;

  /// Deserializes the result from JSON.
  static GetTextResult fromJson(Map<String, dynamic> json) {
30
    return GetTextResult(json['text'] as String);
31 32 33 34 35 36 37 38 39 40 41
  }

  @override
  Map<String, dynamic> toJson() => <String, String>{
    'text': text,
  };
}

/// A Flutter Driver command that enters text into the currently focused widget.
class EnterText extends Command {
  /// Creates a command that enters text into the currently focused widget.
42
  const EnterText(this.text, { super.timeout });
43 44

  /// Deserializes this command from the value generated by [serialize].
45
  EnterText.deserialize(super.json)
46
    : text = json['text']!,
47
      super.deserialize();
48

49 50 51
  /// The text extracted by the [GetText] command.
  final String text;

52
  @override
53
  String get kind => 'enter_text';
54 55 56 57 58 59 60

  @override
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'text': text,
  });
}

61 62 63
/// A Flutter Driver command that enables and disables text entry emulation.
class SetTextEntryEmulation extends Command {
  /// Creates a command that enables and disables text entry emulation.
64
  const SetTextEntryEmulation(this.enabled, { super.timeout });
65 66

  /// Deserializes this command from the value generated by [serialize].
67
  SetTextEntryEmulation.deserialize(super.json)
68
    : enabled = json['enabled'] == 'true',
69
      super.deserialize();
70

71 72 73
  /// Whether text entry emulation should be enabled.
  final bool enabled;

74
  @override
75
  String get kind => 'set_text_entry_emulation';
76 77 78 79 80 81

  @override
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'enabled': '$enabled',
  });
}