copyWith method

LightEffects copyWith({
  1. String? effect,
  2. List<String>? effectValues,
  3. String? status,
  4. List<String>? statusValues,
  5. bool copyOriginalValues = true,
})

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 LightEffects 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

LightEffects copyWith({
  String? effect,
  List<String>? effectValues,
  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);
  }

  LightEffects toReturn = LightEffects(
    effect: copyOriginalValues ? _originalEffect : (effect ?? this.effect),
    effectValues: effectValues ?? List<String>.from(this.effectValues),
    status: status ?? this.status,
    statusValues: statusValues ?? List<String>.from(this.statusValues),
  );

  if (copyOriginalValues) {
    toReturn.effect = effect ?? this.effect;
  }

  return toReturn;
}