maybeOfProperty<T> static method

ModelProperty<T>? maybeOfProperty<T>(
  1. BuildContext context,
  2. Symbol key
)

Optionally find and listen to property changes of the data with the given type from the context. Returns null if the data is not found.

  • T The type of the data.
  • context The build context.
  • key The data key.

Implementation

static ModelProperty<T>? maybeOfProperty<T>(
    BuildContext context, Symbol key) {
  var model = InheritedModel.inheritFrom<_InheritedModel>(context,
      aspect: ModelKey<T>(key));
  if (model == null) {
    return null;
  }
  for (final model in model.data) {
    if (model.dataKey == key && model.dataType == T) {
      if (model is ModelBoundary<T>) {
        return null;
      }
      return model as ModelProperty<T>;
    }
  }
  return null;
}