path property

  1. @override
Path path

Implementation

@override
Path get path {
  if (_path == null) {
    if (parent == null) {
      return _path = Path();
    } else {
      // Maintain a Stack so that the order of the components
      // is reversed when they're added to the Path.
      // We're iterating up the hierarchy from the leaves/children to the root.
      final comps = <Component>[];

      var child = this;
      Container? container = asOrNull<Container>(child.parent);

      while (container != null) {
        var namedChild = asOrNull<NamedContent>(child);
        if (namedChild != null && namedChild.hasValidName) {
          comps.insert(0, Component.name(namedChild.name));
        } else {
          comps.insert(0, Component.index(container.content.indexOf(child)));
        }
        child = container;
        container = asOrNull<Container>(container.parent);
      }
      _path = Path(comps);
    }
  }
  return _path!;
}