of<T extends ChangeNotifier> method

T of<T extends ChangeNotifier>()

Create a dependency between the calling widget and a Bilocator widget with generic 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. or the not match found.

Implementation

T of<T extends ChangeNotifier>() {
  final _BilocatorInheritedWidget<T>? inheritedWidget =
      dependOnInheritedWidgetOfExactType<_BilocatorInheritedWidget<T>>();
  if (inheritedWidget == null) {
    throw Exception(
        'BuildContext.of<T>() did not find inherited widget Bilocator<$T>(). Possible causes:\n'
        ' - The data was stored in the registry instead of the widget tree. To search the registry, do not use '
        'BuildContext.\n\n');
  }
  return inheritedWidget.instance;
}