copyWith method

ScenePalette copyWith({
  1. List<ScenePaletteColor>? colors,
  2. List<LightDimming>? dimmings,
  3. List<ScenePaletteColorTemperature>? colorTemperatures,
  4. bool copyOriginalValues = true,
})

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.

Implementation

ScenePalette copyWith({
  List<ScenePaletteColor>? colors,
  List<LightDimming>? dimmings,
  List<ScenePaletteColorTemperature>? colorTemperatures,
  bool copyOriginalValues = true,
}) {
  ScenePalette toReturn = ScenePalette(
    colors: copyOriginalValues
        ? _originalColors
            .map((color) =>
                color.copyWith(copyOriginalValues: copyOriginalValues))
            .toList()
        : (colors ??
            this
                .colors
                .map((color) =>
                    color.copyWith(copyOriginalValues: copyOriginalValues))
                .toList()),
    dimmings: copyOriginalValues
        ? _originalDimmings
            .map((d) => d.copyWith(copyOriginalValues: copyOriginalValues))
            .toList()
        : (dimmings ??
            this
                .dimmings
                .map(
                    (d) => d.copyWith(copyOriginalValues: copyOriginalValues))
                .toList()),
    colorTemperatures: copyOriginalValues
        ? _originalColorTemperatures
            .map((ct) => ct.copyWith(copyOriginalValues: copyOriginalValues))
            .toList()
        : (colorTemperatures ??
            this
                .colorTemperatures
                .map((ct) =>
                    ct.copyWith(copyOriginalValues: copyOriginalValues))
                .toList()),
  );

  if (copyOriginalValues) {
    toReturn.colors = colors ??
        this
            .colors
            .map((color) =>
                color.copyWith(copyOriginalValues: copyOriginalValues))
            .toList();
    toReturn.dimmings = dimmings ??
        this
            .dimmings
            .map((d) => d.copyWith(copyOriginalValues: copyOriginalValues))
            .toList();
    toReturn.colorTemperatures = colorTemperatures ??
        this
            .colorTemperatures
            .map((ct) => ct.copyWith(copyOriginalValues: copyOriginalValues))
            .toList();
  }

  return toReturn;
}