of<T extends ChangeNotifier> method

T of<T extends ChangeNotifier>()

Create a dependency with a Registrar widget with location param set and a model of type T.

Same idea as the "of" feature of Provider.of, Theme.of, etc. For no dependency, use get. Performs a lazy initialization if necessary. An exception is thrown if T is not a ChangeNotifier.

Implementation

T of<T extends ChangeNotifier>() {
  final _RegistrarInheritedWidget<T>? inheritedWidget =
      dependOnInheritedWidgetOfExactType<_RegistrarInheritedWidget<T>>();
  if (inheritedWidget == null) {
    throw Exception(
        'BuildContext.of<T>() did not find inherited widget Registrar<$T>(inherited: true)');
  }
  return inheritedWidget.instance;
}