prettyMap property

String get prettyMap

Returns a pretty json output from this hierarchy as a printable string

Implementation

String get prettyMap {
  const encoder = JsonEncoder.withIndent('  ');

  Map toMap(List<HierarchySegment> segments) {
    return Map.fromEntries(segments.map(
      (e) => MapEntry(e.name, {
        if (e.pathParams?.isNotEmpty == true) 'pathParams': e.pathParams!.rawMap,
        if (e.queryParams?.isNotEmpty == true) 'queryParams': e.queryParams!.rawMap,
        if (e.children.isNotEmpty) 'children': toMap(e.children),
      }),
    ));
  }

  return encoder.convert(toMap(this));
}