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

import 'message.dart';

7 8
/// A Flutter Driver command that sends a string to the application and expects a
/// string response.
9 10
class RequestData extends Command {
  /// Create a command that sends a message.
11
  const RequestData(this.message, { super.timeout });
12 13

  /// Deserializes this command from the value generated by [serialize].
14 15
  RequestData.deserialize(super.json)
    : message = json['message'],
16
      super.deserialize();
17

18
  /// The message being sent from the test to the application.
19
  final String? message;
20 21

  @override
22
  String get kind => 'request_data';
23

24 25 26
  @override
  bool get requiresRootWidgetAttached => false;

27 28
  @override
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
29 30
    if (message != null)
      'message': message!,
31 32 33 34 35 36
  });
}

/// The result of the [RequestData] command.
class RequestDataResult extends Result {
  /// Creates a result with the given [message].
37
  const RequestDataResult(this.message);
38 39 40 41 42 43

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

  /// Deserializes the result from JSON.
  static RequestDataResult fromJson(Map<String, dynamic> json) {
44
    return RequestDataResult(json['message'] as String);
45 46 47 48 49 50 51
  }

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