dependOn<T extends MomentumController> method

  1. @Deprecated('Use "controller<T>()" instead')
T dependOn<T extends MomentumController>()

Dependency injection method for getting other controllers. Useful for accessing other controllers' function and model properties without dragging the widget context around.

Implementation

@Deprecated('Use "controller<T>()" instead')
T dependOn<T extends MomentumController>() {
  var type = _getType<T>();
  if (runtimeType == type) {
    throw MomentumError(_formatMomentumLog('[$this]: called '
        '"dependOn<$T>()" on itself, you\'re not '
        'allowed to do that.'));
  }
  T? result;
  if (_mRootContext != null) {
    result = Momentum._ofInternal<T>(_mRootContext!);
  } else if (_tester != null) {
    result = _tester!.controller<T>();
  }
  if (result == null) {
    throw MomentumError(_formatMomentumLog('[$this]: called '
        '"dependOn<$T>()", but no controller of type '
        '[$T] had been found.\nTry checking your "Momentum" '
        'root widget implementation if the controller '
        '"$T" was instantiated there.'));
  }
  return result;
}