find<T> method

  1. @override
List<T> find<T>(
  1. dynamic locator,
  2. bool required
)
override

Gets all component references that match specified locator.

  • locator the locator to find a reference by.
  • required forces to raise an exception if no reference is found. Returns a list with matching component references.

Throws a ReferenceException when required is set to true but no references found.

Implementation

@override
List<T> find<T>(locator, bool required) {
  var components = super.find<T>(locator, false);

  // Try to create the component
  if (required && components.isEmpty) {
    var factory = findFactory(locator);
    var component = create(locator, factory);
    if (component != null) {
      try {
        locator = clarifyLocator(locator, factory);
        topReferences!.put(locator, component);
        components.add(component);
      } catch (ex) {
        // Ignore exception
      }
    }
  }

  // Throw exception is no required components found
  if (required && components.isEmpty) {
    throw ReferenceException(null, locator.toString());
  }

  return components;
}