get<T> static method
Allows to get an inherited "property". Used in child components.
Implementation
static T get<T>(String key) {
return VComponent.run((vComponent) {
try {
final context = VContext(context: vComponent.context, key: _key);
if (!context.hasKey(key)) {
VNode? parent = vComponent;
while (parent != null) {
if (parent.kind == VNodeKind.component) {
parent = parent as VComponent;
final parentContext =
VContext(context: parent.context, key: _key);
if (parentContext.hasKey(key)) {
final T value = parentContext.get(key);
return value;
}
}
parent = parent.parent;
}
throw StateError("The property '$key' not found");
} else {
final value = context.get<T>(key);
return value;
}
} catch (e, s) {
throw WrappedException(
"An error occurred while executing the method '$InheritedProperty.get($key)' for component '$vComponent'",
e,
s);
}
});
}