File size: 2,685 Bytes
4e917e6
 
 
 
346a42c
 
 
4e917e6
 
 
 
 
 
 
 
 
 
 
 
 
346a42c
 
 
4e917e6
 
 
 
 
 
 
 
346a42c
 
 
4e917e6
 
 
 
 
 
 
346a42c
 
 
 
4e917e6
 
 
 
 
 
 
 
 
 
 
 
 
 
346a42c
 
 
 
 
 
4e917e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// @docImport 'package:flutter/widgets.dart';
library;

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

/// [DiagnosticsNode] tree types that can be requested by [GetDiagnosticsTree].
enum DiagnosticsType {
  /// The [DiagnosticsNode] tree formed by [RenderObject]s.
  renderObject,

  /// The [DiagnosticsNode] tree formed by [Widget]s.
  widget,
}

EnumIndex<DiagnosticsType> _diagnosticsTypeIndex = EnumIndex<DiagnosticsType>(
  DiagnosticsType.values,
);

/// A Flutter Driver command to retrieve the JSON-serialized [DiagnosticsNode]
/// tree of the object identified by [finder].
///
/// The [DiagnosticsType] of the [DiagnosticsNode] tree returned is specified by
/// [diagnosticsType].
class GetDiagnosticsTree extends CommandWithTarget {
  /// Creates a [GetDiagnosticsTree] Flutter Driver command.
  GetDiagnosticsTree(
    super.finder,
    this.diagnosticsType, {
    this.subtreeDepth = 0,
    this.includeProperties = true,
    super.timeout,
  });

  /// Deserializes this command from the value generated by [serialize].
  GetDiagnosticsTree.deserialize(super.json, super.finderFactory)
    : subtreeDepth = int.parse(json['subtreeDepth']!),
      includeProperties = json['includeProperties'] == 'true',
      diagnosticsType = _diagnosticsTypeIndex.lookupBySimpleName(json['diagnosticsType']!),
      super.deserialize();

  /// How many levels of children to include in the JSON result.
  ///
  /// Defaults to zero, which will only return the [DiagnosticsNode] information
  /// of the object identified by [finder].
  final int subtreeDepth;

  /// Whether the properties of a [DiagnosticsNode] should be included.
  final bool includeProperties;

  /// The type of [DiagnosticsNode] tree that is requested.
  final DiagnosticsType diagnosticsType;

  @override
  Map<String, String> serialize() =>
      super.serialize()..addAll(<String, String>{
        'subtreeDepth': subtreeDepth.toString(),
        'includeProperties': includeProperties.toString(),
        'diagnosticsType': _diagnosticsTypeIndex.toSimpleName(diagnosticsType),
      });

  @override
  String get kind => 'get_diagnostics_tree';
}

/// The result of a [GetDiagnosticsTree] command.
class DiagnosticsTreeResult extends Result {
  /// Creates a [DiagnosticsTreeResult].
  const DiagnosticsTreeResult(this.json);

  /// The JSON encoded [DiagnosticsNode] tree requested by the
  /// [GetDiagnosticsTree] command.
  final Map<String, dynamic> json;

  @override
  Map<String, dynamic> toJson() => json;
}