canCreate method

  1. @override
dynamic canCreate(
  1. dynamic locator
)
override

Checks if this factory is able to create component by given locator.

This method searches for all registered components and returns a locator for component it is able to create that matches the given locator. If the factory is not able to create a requested component is returns null.

  • locator a locator to identify component to be created. Return a locator for a component that the factory is able to create.

Implementation

@override
dynamic canCreate(locator) {
  if (locator == null) {
    throw Exception('Locator cannot be null');
  }

  // Iterate from the latest factories
  for (var index = _factories.length - 1; index >= 0; index--) {
    var thisLocator = _factories[index].canCreate(locator);
    if (thisLocator != null) return thisLocator;
  }

  return null;
}