copyWith method

LightColorTemperatureDelta copyWith({
  1. LightColorTemperatureDeltaAction? action,
  2. int? delta = -1,
  3. bool copyOriginalValues = true,
})

Returns a copy of this object with its field values replaced by the ones provided to this method.

Since delta is nullable, it is defaulted to a negative number in this method. If left as a negative number, its current value in this LightColorTemperatureDelta object will be used. This way, if it is null, the program will know that it is intentionally being set to null.

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.

Implementation

LightColorTemperatureDelta copyWith({
  LightColorTemperatureDeltaAction? action,
  int? delta = -1,
  bool copyOriginalValues = true,
}) {
  LightColorTemperatureDelta toReturn = LightColorTemperatureDelta(
    action: copyOriginalValues ? _originalAction : (action ?? this.action),
    delta: copyOriginalValues
        ? _originalDelta
        : (delta == null || delta >= 0 ? delta : this.delta),
  );

  if (copyOriginalValues) {
    toReturn.action = action ?? this.action;
    toReturn.delta = delta == null || delta >= 0 ? delta : this.delta;
  }

  return toReturn;
}