maybeFindProperty<T> static method

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

Find and listen to property changes of the data with the given type from the context. Throws an assertion error if the data is not found.

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

Implementation

static ModelProperty<T>? maybeFindProperty<T>(
    BuildContext context, Symbol key) {
  final widget = context.findAncestorWidgetOfExactType<_InheritedModel>();
  if (widget == null) {
    return null;
  }
  for (final model in widget.data) {
    if (model.dataKey == key && model.dataType == T) {
      if (model is ModelBoundary<T>) {
        return null;
      }
      return model as ModelProperty<T>;
    }
  }
  return null;
}