Google is committed to advancing racial equity for Black communities. See how.

inspectFromDiagnostic method

  • @visibleForTesting

void inspectFromDiagnostic (dynamic diagnostics, Node parent) @visibleForTesting

Converts an diagnostics tree into a Node tree Creates a Node with Inspect data based on what information was in the DiagnosticsNode and attaches it to the parent

Implementation

@visibleForTesting
static void inspectFromDiagnostic(DiagnosticsNode diagnostics, Node parent) {
  /// Finds the name of the widget and assigns it to the name of the node.
  String name = '';
  for (DiagnosticsNode diagNode in diagnostics.getProperties()) {
    /// Used to obtain the name of the widget by checking which
    /// property is titled "widget"
    if (diagNode.name == 'widget') {
      name = diagNode.value.toString();
      break;
    }
  }

  // If the name of the child does not exist log it and skip that node
  if(name == ''){
    print('Name of node cannot be found');
    return;
  }

  // Adds a hashcode to the name of the node so that the widgets with the same
  // names do not get their properties merged.
  var childNode = parent.child('${name}_${diagnostics.hashCode}');

  /// For each property, add the property to the node.
  for (DiagnosticsNode diagNode in diagnostics.getProperties()) {
    /// If the property isn't null, then get the name of the property
    /// and assign its value. The value of the property can be null
    /// but the property itself cannot be null.
    if (diagNode.name != null) {
      childNode.stringProperty(diagNode.name).setValue(diagNode.toDescription());
    }
  }

  for (DiagnosticsNode diagNode in diagnostics.getChildren()) {
    inspectFromDiagnostic(diagNode, childNode);
  }
}