getSpaces method

Future<List<Space>> getSpaces({
  1. bool recursive = false,
})

Gets all child spaces of this project.

If recursive is true, traverses the entire space tree depth-first and returns every space as a high-level Space model. This keeps the caller insulated from the raw gRPC paging responses.

final spaces = await project.getSpaces();
for (final space in spaces) {
  print(space.path);
}

Implementation

Future<List<Space>> getSpaces({bool recursive = false}) async {
  final spaceResponses = await client.getChildSpaces('/$name');
  final spaces = spaceResponses.map<Space>((s) => Space(s, client)).toList();

  if (recursive && spaces.isNotEmpty) {
    final allSpaces = <Space>[...spaces];
    for (final space in spaces) {
      final children = await space.getChildSpaces(recursive: true);
      allSpaces.addAll(children);
    }
    return allSpaces;
  }

  return spaces;
}