copyWith method

Light copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. Relative? owner,
  5. LightMetadata? metadata,
  6. LightOn? on,
  7. LightDimmingFull? dimming,
  8. Object? dimmingDelta = sentinelValue,
  9. LightColorTemperature? colorTemperature,
  10. Object? colorTemperatureDelta = sentinelValue,
  11. LightColor? color,
  12. LightDynamics? dynamics,
  13. LightAlert? alert,
  14. LightSignaling? signaling,
  15. LightMode? mode,
  16. LightGradientFull? gradient,
  17. LightEffects? effects,
  18. LightTimedEffects? timedEffects,
  19. LightPowerUp? powerUp,
  20. bool copyOriginalValues = true,
})

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

Since dimmingDelta and colorTemperatureDelta are nullable, they are defaulted to empty objects in this method. If left as empty objects, their current value in this Light object will be used. This way, if they are null, the program will know that they are 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

Light copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  Relative? owner,
  LightMetadata? metadata,
  LightOn? on,
  LightDimmingFull? dimming,
  Object? dimmingDelta = sentinelValue,
  LightColorTemperature? colorTemperature,
  Object? colorTemperatureDelta = sentinelValue,
  LightColor? color,
  LightDynamics? dynamics,
  LightAlert? alert,
  LightSignaling? signaling,
  LightMode? mode,
  LightGradientFull? gradient,
  LightEffects? effects,
  LightTimedEffects? timedEffects,
  LightPowerUp? powerUp,
  bool copyOriginalValues = true,
}) {
  if (!identical(dimmingDelta, sentinelValue)) {
    assert(dimmingDelta is LightDimmingDelta?,
        "`dimmingDelta` must be a `LightDimmingDelta?` object");
  }
  if (!identical(colorTemperatureDelta, sentinelValue)) {
    assert(colorTemperatureDelta is LightColorTemperatureDelta?,
        "`colorTemperatureDelta` must be a `LightColorTemperatureDelta?` object");
  }

  Light toReturn = Light(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    owner:
        owner ?? this.owner.copyWith(copyOriginalValues: copyOriginalValues),
    metadata: copyOriginalValues
        ? _originalMetadata.copyWith(copyOriginalValues: copyOriginalValues)
        : (metadata ??
            this.metadata.copyWith(copyOriginalValues: copyOriginalValues)),
    on: copyOriginalValues
        ? _originalOn.copyWith(copyOriginalValues: copyOriginalValues)
        : (on ?? this.on.copyWith(copyOriginalValues: copyOriginalValues)),
    dimming: copyOriginalValues
        ? _originalDimming.copyWith(copyOriginalValues: copyOriginalValues)
        : (dimming ??
            this.dimming.copyWith(copyOriginalValues: copyOriginalValues)),
    dimmingDelta: copyOriginalValues
        ? _originalDimmingDelta?.copyWith(
            copyOriginalValues: copyOriginalValues)
        : (identical(dimmingDelta, sentinelValue)
            ? this
                .dimmingDelta
                ?.copyWith(copyOriginalValues: copyOriginalValues)
            : dimmingDelta as LightDimmingDelta?),
    colorTemperature: copyOriginalValues
        ? _originalColorTemperature.copyWith(
            copyOriginalValues: copyOriginalValues)
        : (colorTemperature ??
            this
                .colorTemperature
                .copyWith(copyOriginalValues: copyOriginalValues)),
    colorTemperatureDelta: copyOriginalValues
        ? _originalColorTemperatureDelta?.copyWith(
            copyOriginalValues: copyOriginalValues)
        : (identical(colorTemperatureDelta, sentinelValue)
            ? this
                .colorTemperatureDelta
                ?.copyWith(copyOriginalValues: copyOriginalValues)
            : colorTemperatureDelta as LightColorTemperatureDelta?),
    color: copyOriginalValues
        ? _originalColor.copyWith(copyOriginalValues: copyOriginalValues)
        : (color ??
            this.color.copyWith(copyOriginalValues: copyOriginalValues)),
    dynamics: copyOriginalValues
        ? _originalDynamics.copyWith(copyOriginalValues: copyOriginalValues)
        : (dynamics ??
            this.dynamics.copyWith(copyOriginalValues: copyOriginalValues)),
    alert: copyOriginalValues
        ? _originalAlert.copyWith(copyOriginalValues: copyOriginalValues)
        : (alert ??
            this.alert.copyWith(copyOriginalValues: copyOriginalValues)),
    signaling: signaling ?? this.signaling.copyWith(),
    mode: mode ?? this.mode,
    gradient: copyOriginalValues
        ? _originalGradient.copyWith(copyOriginalValues: copyOriginalValues)
        : (gradient ??
            this.gradient.copyWith(copyOriginalValues: copyOriginalValues)),
    effects: copyOriginalValues
        ? _originalEffects.copyWith(copyOriginalValues: copyOriginalValues)
        : (effects ??
            this.effects.copyWith(copyOriginalValues: copyOriginalValues)),
    timedEffects: copyOriginalValues
        ? _originalTimedEffects.copyWith(
            copyOriginalValues: copyOriginalValues)
        : timedEffects ??
            this
                .timedEffects
                .copyWith(copyOriginalValues: copyOriginalValues),
    powerUp: copyOriginalValues
        ? _originalPowerUp.copyWith(copyOriginalValues: copyOriginalValues)
        : (powerUp ??
            this.powerUp.copyWith(copyOriginalValues: copyOriginalValues)),
  );

  if (copyOriginalValues) {
    toReturn.type = type ?? this.type;
    toReturn.metadata = metadata ??
        this.metadata.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.on =
        on ?? this.on.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.dimming = dimming ??
        this.dimming.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.dimmingDelta = identical(dimmingDelta, sentinelValue)
        ? this.dimmingDelta?.copyWith(copyOriginalValues: copyOriginalValues)
        : dimmingDelta as LightDimmingDelta?;
    toReturn.colorTemperature = colorTemperature ??
        this
            .colorTemperature
            .copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.colorTemperatureDelta =
        identical(colorTemperatureDelta, sentinelValue)
            ? this
                .colorTemperatureDelta
                ?.copyWith(copyOriginalValues: copyOriginalValues)
            : colorTemperatureDelta as LightColorTemperatureDelta?;
    toReturn.color =
        color ?? this.color.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.dynamics = dynamics ??
        this.dynamics.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.alert =
        alert ?? this.alert.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.gradient = gradient ??
        this.gradient.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.effects = effects ??
        this.effects.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.timedEffects = timedEffects ??
        this.timedEffects.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.powerUp = powerUp ??
        this.powerUp.copyWith(copyOriginalValues: copyOriginalValues);
  }

  return toReturn;
}