jsonDump method
Prints all pathes of the scope or its parent
If parentDepth < 0, start at the root If childDepth < 0, show all children
Implementation
Map<String, dynamic> jsonDump({
int parentDepth = 0,
int childDepth = -1,
bool sourceNodesOnly = false,
bool removeEmptyScopes = false,
bool throwOnNonSerializableTypes = false,
}) {
var start = this;
// If parentDepth < 0, start at the root
if (parentDepth < 0) {
parentDepth = 0xFFFF;
}
// Find parent node that matches the parentDepth
var realParentDepth = 0;
while (parentDepth > 0 && start.parent != null) {
start = start.parent!;
realParentDepth++;
parentDepth--;
}
// If childDepth > 0, we need to add the parent depth to childDepth
if (childDepth > 0) {
childDepth += realParentDepth;
}
// Define the result array
final result = <String, dynamic>{};
// Write the tree
_jsonDump(
scope: start,
result: result,
depth: childDepth,
infinite: childDepth < 0,
sourceNodesOnly: sourceNodesOnly,
throwOnNonSerializableTypes: throwOnNonSerializableTypes,
);
if (removeEmptyScopes) {
_removeEmptyScopes(result);
}
return result;
}