addDynamic method

void addDynamic(
  1. String key,
  2. Object? value, [
  3. ContextualResource<T, C> mapper(
    1. Object? value
    )?
])

Adds a resources with a dynamic value.

Implementation

void addDynamic(String key, Object? value,
    [ContextualResource<T, C> Function(Object? value)? mapper]) {
  if (value is ContextualResource) {
    if (mapper != null) {
      value = mapper(value);
    }
    add(key, [value as ContextualResource<T, C>]);
  } else if (value is Iterable) {
    for (var e in value) {
      if (mapper != null) {
        e = mapper(e);
      }
      addDynamic(key, e);
    }
  } else if (value is Function) {
    var v = value(key);
    if (mapper != null) {
      v = mapper(v);
    }
    addDynamic(key, v);
  }
}