copyWith method

LightDimmingDelta copyWith({
  1. LightDimmingDeltaAction? action,
  2. double? delta = -1.0,
  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 LightDimmingDelta 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

LightDimmingDelta copyWith({
  LightDimmingDeltaAction? action,
  double? delta = -1.0,
  bool copyOriginalValues = true,
}) {
  LightDimmingDelta toReturn = LightDimmingDelta(
    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;
}