| 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import 'find.dart'; |
| 6 | import 'message.dart'; |
| 7 | |
| 8 | /// A Flutter Driver command that reads the text from a given element. |
| 9 | class GetText extends CommandWithTarget { |
| 10 | /// [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 | /// The result of the [GetText] command. |
| 21 | class GetTextResult extends Result { |
| 22 | /// Creates a result with the given [text]. |
| 23 | const GetTextResult(this.text); |
| 24 | |
| 25 | /// The text extracted by the [GetText] command. |
| 26 | final String text; |
| 27 | |
| 28 | /// Deserializes the result from JSON. |
| 29 | static GetTextResult fromJson(Map<String, dynamic> json) { |
| 30 | return GetTextResult(json['text' ] as String); |
| 31 | } |
| 32 | |
| 33 | @override |
| 34 | Map<String, dynamic> toJson() => <String, String>{'text' : text}; |
| 35 | } |
| 36 | |
| 37 | /// A Flutter Driver command that enters text into the currently focused widget. |
| 38 | class EnterText extends Command { |
| 39 | /// Creates a command that enters text into the currently focused widget. |
| 40 | const EnterText(this.text, {super.timeout}); |
| 41 | |
| 42 | /// Deserializes this command from the value generated by [serialize]. |
| 43 | EnterText.deserialize(super.json) : text = json['text' ]!, super.deserialize(); |
| 44 | |
| 45 | /// The text extracted by the [GetText] command. |
| 46 | final String text; |
| 47 | |
| 48 | @override |
| 49 | String get kind => 'enter_text' ; |
| 50 | |
| 51 | @override |
| 52 | Map<String, String> serialize() => super.serialize()..addAll(<String, String>{'text' : text}); |
| 53 | } |
| 54 | |
| 55 | /// A Flutter Driver command that enables and disables text entry emulation. |
| 56 | class SetTextEntryEmulation extends Command { |
| 57 | /// Creates a command that enables and disables text entry emulation. |
| 58 | const SetTextEntryEmulation(this.enabled, {super.timeout}); |
| 59 | |
| 60 | /// Deserializes this command from the value generated by [serialize]. |
| 61 | SetTextEntryEmulation.deserialize(super.json) |
| 62 | : enabled = json['enabled' ] == 'true' , |
| 63 | super.deserialize(); |
| 64 | |
| 65 | /// Whether text entry emulation should be enabled. |
| 66 | final bool enabled; |
| 67 | |
| 68 | @override |
| 69 | String get kind => 'set_text_entry_emulation' ; |
| 70 | |
| 71 | @override |
| 72 | Map<String, String> serialize() => |
| 73 | super.serialize()..addAll(<String, String>{'enabled' : ' $enabled' }); |
| 74 | } |
| 75 | |