semantics.dart 1.5 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
/// A Flutter Driver command that enables or disables semantics.
8
class SetSemantics extends Command {
9
  /// Creates a command that enables or disables semantics.
10
  const SetSemantics(this.enabled, { Duration? timeout }) : super(timeout: timeout);
11

12 13
  /// Deserializes this command from the value generated by [serialize].
  SetSemantics.deserialize(Map<String, String> params)
14
    : enabled = params['enabled']!.toLowerCase() == 'true',
15
      super.deserialize(params);
16

17 18 19 20
  /// Whether semantics should be enabled (true) or disabled (false).
  final bool enabled;

  @override
21
  String get kind => 'set_semantics';
22

23 24 25 26 27 28 29 30
  @override
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'enabled': '$enabled',
  });
}

/// The result of a [SetSemantics] command.
class SetSemanticsResult extends Result {
31
  /// Create a result with the given [changedState].
32
  const SetSemanticsResult(this.changedState);
33

34 35
  /// Whether the [SetSemantics] command actually changed the state that the
  /// application was in.
36 37 38 39
  final bool changedState;

  /// Deserializes this result from JSON.
  static SetSemanticsResult fromJson(Map<String, dynamic> json) {
40
    return SetSemanticsResult(json['changedState'] as bool);
41 42 43 44 45 46 47
  }

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