getService<T extends MomentumService> method

  1. @Deprecated('Use "service<T>()" instead')
T getService<T extends MomentumService>({
  1. bool runtimeType = true,
  2. dynamic alias,
})

A method for getting a service marked with MomentumService that are injected into Momentum root widget.

Implementation

@Deprecated('Use "service<T>()" instead')
T getService<T extends MomentumService>({bool runtimeType = true, dynamic alias}) {
  try {
    if (_mRootContext == null && _tester != null) {
      return _tester!.service<T>(runtimeType: runtimeType, alias: alias);
    }
    var result = Momentum.service<T>(_mRootContext!, runtimeType: runtimeType, alias: alias);
    return result;
  } catch (e) {
    if (_momentumLogging!) {
      print(e);
    }
    throw MomentumError(_formatMomentumLog('[$this]: called '
        '"dependOn<$T>()", but no service of type [$T] '
        'had been found.\nTry checking your "Momentum" '
        'root widget implementation if the service "$T" '
        'was instantiated there.'));
  }
}