add<T> static method

T add<T>(
  1. String key,
  2. T init()
)

Adds an inherited "property". Used in the parent component.

Implementation

static T add<T>(String key, T Function() init) {
  return VComponent.run((vComponent) {
    final context = VContext(context: vComponent.context, key: _key);
    if (!context.hasKey(key)) {
      try {
        final value = context.init(key, init);
        return value;
      } catch (e, s) {
        throw WrappedException(
            "An error occurred while executing the method '$InheritedProperty.add($key)' for component '$vComponent'",
            e,
            s);
      }
    } else {
      return context.get(key);
    }
  });
}