reduce method

  1. @override
St reduce ()
override

The reduce method is the action reducer. It may read the action state, the store state, and then return a new state (or null if no state change is necessary).

It may be synchronous (returning AppState or null) or async (returning Future<AppState> or Future<null>).

The StoreConnectors may rebuild only if the reduce method returns a state which is both not null and different from the previous one (comparing by identical, not equals).

Implementation

@override
St reduce() {
  if (_navigatorKey != null)
    switch (navigateType) {
      //
      case NavigateType.push:
        _navigatorKey.currentState.push(route);
        break;

      case NavigateType.pop:
        _navigatorKey.currentState.pop();
        break;

      case NavigateType.pushNamed:
        _navigatorKey.currentState.pushNamed(routeName, arguments: arguments);
        break;

      case NavigateType.pushReplacementNamed:
        _navigatorKey.currentState.pushReplacementNamed(routeName, arguments: arguments);
        break;

      case NavigateType.pushNamedAndRemoveAll:
        _navigatorKey.currentState.pushNamedAndRemoveUntil(
            routeName, (Route<dynamic> route) => false,
            arguments: arguments);
        break;

      case NavigateType.pushNamedAndRemoveUntil:
        _navigatorKey.currentState
            .pushNamedAndRemoveUntil(routeName, predicate, arguments: arguments);
        break;

      case NavigateType.popUntil:
        _navigatorKey.currentState.popUntil(
          (Route<dynamic> route) => route.settings.name == routeName,
        );
        break;

      default:
        throw StoreException("Navigation not yet supported: $navigateType");
    }

  return null;
}