getByType<A extends APIRoot> static method

A? getByType<A extends APIRoot>({
  1. Type? type,
  2. bool lastAsDefault = false,
})

Returns an APIRoot instance by type.

Implementation

static A? getByType<A extends APIRoot>(
    {Type? type, bool lastAsDefault = false}) {
  type ??= A;

  var apiRoot =
      _instances.values.firstWhereOrNull((e) => e.runtimeType == type);
  if (apiRoot != null) return apiRoot as A;

  apiRoot = _instances.values.firstWhereOrNull((e) => e is A);
  if (apiRoot != null) return apiRoot as A;

  return lastAsDefault ? get(singleton: false) as A? : null;
}