Dart immutability

Viewed 1297
AuthState copy({
    FirebaseUser firebaseUser,
    String token,

    List<Map> contracts,
    bool loadingContracts,
    String contractsError,

    List<Map> searchModules,
    bool loadingSearchModules,
    String searchModulesError
  }) {
    AuthState state = new AuthState(
        firebaseUser ??= this.firebaseUser,

        token ??= this.token,

        contracts ??= this.contracts,
        loadingContracts ??= this.loadingContracts,
        contractsError ??= this.contractsError,

        searchModules ??= this.searchModules,
        loadingSearchModules ??= this.loadingSearchModules,
        searchModulesError ??= this.searchModulesError
    );

I am using Redux so every time a action is dispatched you need to create a new state.

When I use ?? and not provide a parameter the value will be set to null, so that is not what I want. If I use ??= it will assign object's property to the new value. But it is unable to set to value to null when I explicitly set the param to null.

I am walking around with this problem for a few days now. Would be amazing if someone could help me.

Btw I am building a Flutter app with https://github.com/alexeieleusis/greencat as Redux library.

1 Answers
Related