copyWith method

SceneActionAction copyWith({
  1. LightOn? on,
  2. LightDimming? dimming,
  3. LightColorXy? xy,
  4. LightPowerUpColorColorTemperature? colorTemperature,
  5. LightGradient? gradient,
  6. String? effect,
  7. int? durationMilliseconds = -1,
  8. bool copyOriginalValues = true,
})

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

Since durationMilliseconds is nullable, it is defaulted to a negative number in this method. If left as a negative number, its current value in this SceneActionAction 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

SceneActionAction copyWith({
  LightOn? on,
  LightDimming? dimming,
  LightColorXy? xy,
  LightPowerUpColorColorTemperature? colorTemperature,
  LightGradient? gradient,
  String? effect,
  int? durationMilliseconds = -1,
  bool copyOriginalValues = true,
}) {
  SceneActionAction toReturn = SceneActionAction(
    on: copyOriginalValues
        ? _originalOn.copyWith(copyOriginalValues: copyOriginalValues)
        : (on ?? this.on.copyWith(copyOriginalValues: copyOriginalValues)),
    dimming: copyOriginalValues
        ? _originalDimming.copyWith(copyOriginalValues: copyOriginalValues)
        : (dimming ??
            this.dimming.copyWith(copyOriginalValues: copyOriginalValues)),
    xy: copyOriginalValues
        ? _originalXy.copyWith(copyOriginalValues: copyOriginalValues)
        : (xy ?? this.xy.copyWith(copyOriginalValues: copyOriginalValues)),
    colorTemperature: copyOriginalValues
        ? _originalColorTemperature.copyWith(
            copyOriginalValues: copyOriginalValues)
        : (colorTemperature ??
            this
                .colorTemperature
                .copyWith(copyOriginalValues: copyOriginalValues)),
    gradient: copyOriginalValues
        ? _originalGradient.copyWith(copyOriginalValues: copyOriginalValues)
        : (gradient ??
            this.gradient.copyWith(copyOriginalValues: copyOriginalValues)),
    effect: copyOriginalValues ? _originalEffect : (effect ?? this.effect),
    durationMilliseconds: copyOriginalValues
        ? _originalDurationMilliseconds
        : (durationMilliseconds == null || durationMilliseconds >= 0
            ? durationMilliseconds
            : this.durationMilliseconds),
  );

  if (copyOriginalValues) {
    toReturn.on =
        on ?? this.on.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.dimming = dimming ??
        this.dimming.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.xy =
        xy ?? this.xy.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.colorTemperature = colorTemperature ??
        this
            .colorTemperature
            .copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.gradient = gradient ??
        this.gradient.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.effect = effect ?? this.effect;
    toReturn.durationMilliseconds =
        durationMilliseconds == null || durationMilliseconds >= 0
            ? durationMilliseconds
            : this.durationMilliseconds;
  }

  return toReturn;
}