of<T> static method

T of<T>(
  1. BuildContext context, {
  2. bool rebuild = false,
})

Implementation

static T of<T>(
  BuildContext context, {
  bool rebuild = false,
  // Object Function(T value)? filter,
}) {
  final inheritedElement =
      context.getElementForInheritedWidgetOfExactType<Binder<T>>()
          as BindElement<T>?;

  if (inheritedElement == null) {
    throw BindError(controller: '$T', tag: null);
  }

  if (rebuild) {
    // var newFilter = filter?.call(inheritedElement.controller!);
    // if (newFilter != null) {
    //  context.dependOnInheritedElement(inheritedElement, aspect: newFilter);
    // } else {
    context.dependOnInheritedElement(inheritedElement);
    // }
  }

  final controller = inheritedElement.controller;

  return controller;
}