parent property

Future get parent

Gets the parent of this space.

Returns the parent Space if this is a nested space, or the parent Project if this is a root-level space (directly under project).

final parent = await space.parent;
if (parent is Space) {
  print('Parent space: ${parent.path}');
} else if (parent is Project) {
  print('Parent project: ${parent.name}');
}

Implementation

Future<dynamic> get parent async {
  final parts = path.split('/').where((s) => s.isNotEmpty).toList();

  // Root-level space (e.g., /project/space) - parent is the project
  if (parts.length <= 2) {
    return project;
  }

  // Nested space - parent is another space
  final parentPath = '/${parts.sublist(0, parts.length - 1).join('/')}';
  try {
    final response = await client.getSpace(parentPath);
    return Space(response, client);
  } catch (_) {
    // Fallback to project if space lookup fails
    return project;
  }
}