copyWith method
Returns a copy of this object with its field values replaced by the ones provided to this method.
copyOriginalValues
is true if you want to maintain the original object's
initial values. This is useful if you plan on using this object in a PUT
request.
Throws InvalidValueException if the LightTimedEffects copy has an
effect
that is not in its effectValues
array or if it has a status
that is not in its statusValues
array.
Implementation
LightTimedEffects copyWith({
String? effect,
List<String>? effectValues,
int? duration,
String? status,
List<String>? statusValues,
bool copyOriginalValues = true,
}) {
// Make sure [effect] is valid.
if (effectValues != null &&
effect == null &&
!Validators.isValidValue(this.effect, effectValues)) {
throw InvalidValueException.withValue(this.effect, effectValues);
}
// Make sure [status] is valid.
if (statusValues != null &&
status == null &&
!Validators.isValidValue(this.status, statusValues)) {
throw InvalidValueException.withValue(this.status, statusValues);
}
LightTimedEffects toReturn = LightTimedEffects(
effect: copyOriginalValues ? _originalEffect : (effect ?? this.effect),
effectValues: effectValues ?? List<String>.from(this.effectValues),
duration:
copyOriginalValues ? _originalDuration : (duration ?? this.duration),
status: status ?? this.status,
statusValues: statusValues ?? List<String>.from(this.statusValues),
);
if (copyOriginalValues) {
toReturn.effect = effect ?? this.effect;
toReturn.duration = duration ?? this.duration;
}
return toReturn;
}