copyWith method
LightGradientFull
copyWith({
- List<
LightColorXy> ? points, - String? mode,
- List<
String> ? modeValues, - int? pointsCapable,
- int? pixelCount,
- bool copyOriginalValues = true,
override
Returns a copy of this object with its field values replaced by the ones provided to this method.
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.
Throws GradientException if points
has more than 5 elements.
Throws InvalidValueException if the LightGradient copy has a mode
that is not in its modeValues
array.
Implementation
@override
LightGradientFull copyWith({
List<LightColorXy>? points,
String? mode,
List<String>? modeValues,
int? pointsCapable,
int? pixelCount,
bool copyOriginalValues = true,
}) {
// Make sure the gradient is valid.
if (!Validators.isValidGradientDraft(points)) {
throw GradientException.withValue(points?.length ?? -1);
}
// Make sure the mode is valid.
if (modeValues != null &&
mode == null &&
!Validators.isValidValue(this.mode, modeValues)) {
throw InvalidValueException.withValue(this.mode, modeValues);
}
LightGradientFull toReturn = LightGradientFull(
points: copyOriginalValues
? originalPoints
.map((point) =>
point.copyWith(copyOriginalValues: copyOriginalValues))
.toList()
: (points ??
this
.points
.map((point) =>
point.copyWith(copyOriginalValues: copyOriginalValues))
.toList()),
mode: copyOriginalValues ? originalMode : (mode ?? this.mode),
modeValues: modeValues ?? List<String>.from(this.modeValues),
pointsCapable: pointsCapable ?? this.pointsCapable,
pixelCount: pixelCount ?? this.pixelCount,
);
if (copyOriginalValues) {
toReturn.points = points ??
this
.points
.map((point) =>
point.copyWith(copyOriginalValues: copyOriginalValues))
.toList();
toReturn.mode = mode ?? this.mode;
}
return toReturn;
}