I want to avoid writing these three lines over and over in different functions.
var newState = state.copy();
newState.user.googleUser = googleUser;
state = newState;
Something like this?
state = (state.copy().user.googleUser = googleUser);
CodePudding user response:
Use the cascade operator:
state = state.copy()..user.googleUser = googleUser;
Alternatively, a common pattern is to instead create a copyWith
method for your classes so that you can do:
state = state.copyWith(user: googleUser);