copyWith method
GroupedLight
copyWith({
- ResourceType? type,
- String? id,
- String? idV1,
- Relative? owner,
- LightOn? on,
- LightDimming? dimming,
- Object? dimmingDelta = sentinelValue,
- Object? colorTemperature = sentinelValue,
- Object? colorTemperatureDelta = sentinelValue,
- Object? xy = sentinelValue,
- LightAlert? alert,
- int? durationMilliseconds = -1,
- 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 LightDynamics 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
GroupedLight copyWith({
ResourceType? type,
String? id,
String? idV1,
Relative? owner,
LightOn? on,
LightDimming? dimming,
Object? dimmingDelta = sentinelValue,
Object? colorTemperature = sentinelValue,
Object? colorTemperatureDelta = sentinelValue,
Object? xy = sentinelValue,
LightAlert? alert,
int? durationMilliseconds = -1,
bool copyOriginalValues = true,
}) {
if (!identical(dimmingDelta, sentinelValue)) {
assert(dimmingDelta is LightDimmingDelta?,
"`dimmingDelta` must be a `LightDimmingDelta?` object");
}
if (!identical(colorTemperature, sentinelValue)) {
assert(colorTemperature is LightPowerUpColorColorTemperature?,
"`colorTemperature` must be a `LightPowerUpColorColorTemperature?` object");
}
if (!identical(colorTemperatureDelta, sentinelValue)) {
assert(colorTemperatureDelta is LightColorTemperatureDelta?,
"`colorTemperatureDelta` must be a `LightColorTemperatureDelta?` object");
}
if (!identical(xy, sentinelValue)) {
assert(xy is LightColorXy?, "`xy` must be a `LightColorXy?` object");
}
GroupedLight toReturn = GroupedLight(
type: copyOriginalValues ? originalType : (type ?? this.type),
id: id ?? this.id,
idV1: idV1 ?? this.idV1,
owner:
owner ?? this.owner.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)
: (identical(colorTemperature, sentinelValue)
? this
.colorTemperature
?.copyWith(copyOriginalValues: copyOriginalValues)
: colorTemperature as LightPowerUpColorColorTemperature?),
colorTemperatureDelta: copyOriginalValues
? _originalColorTemperatureDelta?.copyWith(
copyOriginalValues: copyOriginalValues)
: (identical(colorTemperatureDelta, sentinelValue)
? this
.colorTemperatureDelta
?.copyWith(copyOriginalValues: copyOriginalValues)
: colorTemperatureDelta as LightColorTemperatureDelta?),
xy: copyOriginalValues
? _originalXy?.copyWith(copyOriginalValues: copyOriginalValues)
: (identical(xy, sentinelValue)
? this.xy?.copyWith(copyOriginalValues: copyOriginalValues)
: xy as LightColorXy?),
alert: copyOriginalValues
? _originalAlert.copyWith(copyOriginalValues: copyOriginalValues)
: (alert ??
this.alert.copyWith(copyOriginalValues: copyOriginalValues)),
durationMilliseconds: copyOriginalValues
? _originalDurationMilliseconds
: (durationMilliseconds == null || durationMilliseconds >= 0
? durationMilliseconds
: this.durationMilliseconds),
);
if (copyOriginalValues) {
toReturn.type = type ?? this.type;
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 = identical(colorTemperature, sentinelValue)
? this
.colorTemperature
?.copyWith(copyOriginalValues: copyOriginalValues)
: colorTemperature as LightPowerUpColorColorTemperature?;
toReturn.colorTemperatureDelta =
identical(colorTemperatureDelta, sentinelValue)
? this
.colorTemperatureDelta
?.copyWith(copyOriginalValues: copyOriginalValues)
: colorTemperatureDelta as LightColorTemperatureDelta?;
toReturn.xy = identical(xy, sentinelValue)
? this.xy?.copyWith(copyOriginalValues: copyOriginalValues)
: xy as LightColorXy?;
toReturn.alert =
alert ?? this.alert.copyWith(copyOriginalValues: copyOriginalValues);
toReturn.durationMilliseconds =
durationMilliseconds == null || durationMilliseconds >= 0
? durationMilliseconds
: this.durationMilliseconds;
}
return toReturn;
}