request_data.dart 1.46 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, { Duration timeout }) : super(timeout: timeout);
12 13 14

  /// Deserializes this command from the value generated by [serialize].
  RequestData.deserialize(Map<String, String> params)
15 16
    : message = params['message'],
      super.deserialize(params);
17

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

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

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

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

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

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

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

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