getParam<T extends RouterParam> method

T? getParam<T extends RouterParam>()

Get the current route parameters specified using the params parameter in MomentumRouter.goto(...) method.

Example:

// setting the route params.
MomentumRouter.goto(context, DashboardPage, params: DashboardParams(...));

// accessing the route params inside widgets.
var params = MomentumRouter.getParam<DashboardParams>(context);

// accessing the route params inside controllers.
var params = getParam<DashboardParams>();

Implementation

T? getParam<T extends RouterParam>() {
  if (_mRootContext == null && _tester != null) {
    var router = _tester!._getRouterIfPresent();
    if (router != null) {
      var param = router.getCurrentParam<T>();
      if (param != null && param.runtimeType == _getType<T>()) {
        return param;
      }
      print(
          'getParam<$T>() ---> Invalid type: The active/current route param is of type "${param.runtimeType}" while the parameter you want to access is of type "$T". Momentum will return a null instead.');
    }
    return null;
  }
  var result = MomentumRouter.getParam<T>(_mRootContext!);
  return result;
}