copyWith method

SmartScene copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. SmartSceneMetadata? metadata,
  5. Relative? group,
  6. List<SmartSceneWeek>? weekTimeslots,
  7. SmartSceneActiveTimeslot? activeTimeslot,
  8. String? state,
  9. String? recallAction = "",
  10. bool copyOriginalValues = true,
})

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

Since recallAction is nullable, it is defaulted to an empty string in this method. If left as an empty string, its current value in this SmartScene 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

SmartScene copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  SmartSceneMetadata? metadata,
  Relative? group,
  List<SmartSceneWeek>? weekTimeslots,
  SmartSceneActiveTimeslot? activeTimeslot,
  String? state,
  String? recallAction = "",
  bool copyOriginalValues = true,
}) {
  SmartScene toReturn = SmartScene(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    metadata: copyOriginalValues
        ? _originalMetadata.copyWith(copyOriginalValues: copyOriginalValues)
        : (metadata ??
            this.metadata.copyWith(copyOriginalValues: copyOriginalValues)),
    group: group ?? this.group,
    weekTimeslots: copyOriginalValues
        ? _originalWeekTimeslots
            .map((weekTimeslot) =>
                weekTimeslot.copyWith(copyOriginalValues: copyOriginalValues))
            .toList()
        : (weekTimeslots ??
            this
                .weekTimeslots
                .map((weekTimeslot) => weekTimeslot.copyWith(
                    copyOriginalValues: copyOriginalValues))
                .toList()),
    activeTimeslot: activeTimeslot ?? this.activeTimeslot,
    state: state ?? this.state,
    recallAction: copyOriginalValues
        ? _originalRecallAction
        : (recallAction == null || recallAction.isNotEmpty
            ? recallAction
            : this.recallAction),
  );

  if (copyOriginalValues) {
    toReturn.type = type ?? this.type;
    toReturn.metadata = metadata ??
        this.metadata.copyWith(copyOriginalValues: copyOriginalValues);
    toReturn.weekTimeslots = weekTimeslots ??
        this
            .weekTimeslots
            .map((weekTimeslot) =>
                weekTimeslot.copyWith(copyOriginalValues: copyOriginalValues))
            .toList();
    toReturn.recallAction = recallAction == null || recallAction.isNotEmpty
        ? recallAction
        : this.recallAction;
  }

  return toReturn;
}