factory property

PositionComponent Function(int amount) get factory

The function used to create a new component to spawn.

amount is the amount of components that the SpawnComponent has spawned so far.

Be aware: internally the component uses a factory that creates a list of components. If you have set such a factory it was wrapped to create a list. The factory getter wraps it again to return the first element of the list and fails when the list is empty!

Implementation

PositionComponent Function(int amount) get factory => (int amount) {
      final result = multiFactory.call(amount);
      assert(
        result.isNotEmpty,
        'The factory call yielded no result, which is required when calling'
        ' the single result factory',
      );
      return result.elementAt(0);
    };
set factory (PositionComponent newFactory(int amount))

Implementation

set factory(PositionComponent Function(int amount) newFactory) {
  multiFactory = _wrapFactory(newFactory);
}