find<T> method
- dynamic locator,
- 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) {
if (locator == null) throw Exception('Locator cannot be null');
var components = <T>[];
// Search all references
for (var index = _references.length - 1; index >= 0; index--) {
var reference = _references[index];
if (reference.match(locator)) {
var component = reference.getComponent() as T;
if (component != null) components.add(component);
}
}
if (components.isEmpty && required) {
throw ReferenceException(null, locator);
}
return components;
}