register<T extends Object> method

void register<T extends Object>(
  1. BuildContext context, {
  2. String? name,
})
inherited

Registers an inherited object.

register is a handy but rarely needed function. Bilocator(location: Location.tree) widgets are accessible from their descendants only. Occasionally, access is required by a widget that is not a descendant. In such cases, you can make the inherited model globally available by registering it. name is assigned to the registered model. name is NOT used for locating the object.

Registered inherited models are unregister when their corresponding Bilocator widget is disposed.

Implementation

void register<T extends Object>(BuildContext context, {String? name}) {
  context._getInheritedWidget<T>().registered.value = true;
  Bilocator.register<T>(instance: context.get<T>(), name: name);
}