get<T extends Object> method

T get<T extends Object>({
  1. BuildContext? context,
  2. String? name,
  3. Filter? filter,
})
inherited

Gets (but does not listen to) a single service or inherited widget.

If context is null, gets a single service from the registry. If context is non-null, gets an inherited model from an ancestor located by context. name is the used when locating a single service but not an inherited model. filter is a custom function that receives a list of the names of all the registered objects of type T and returns a String? that specifies which name to select. For example, if the registry contained objects of type BookPage with names "Page 3", "Page 4", and "Page 5", and you wanted to get the first one found:

final BookPage firstLetter = Bilocator.get<GreekLetter>(filter: (pageNames) => pageNames[0]);

Implementation

T get<T extends Object>(
    {BuildContext? context, String? name, Filter? filter}) {
  assert(context == null || name == null,
      '"get" was passed a non-null value for "name" but cannot locate an inherited model by name.');
  if (context == null) {
    return Bilocator.get<T>(name: name, filter: filter);
  } else {
    return context.get<T>();
  }
}