copyWith method

Zone copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. List<Relative>? children,
  5. List<Relative>? services,
  6. RoomMetadata? metadata,
  7. 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

Zone copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  List<Relative>? children,
  List<Relative>? services,
  RoomMetadata? metadata,
  bool copyOriginalValues = true,
}) {
  Zone toReturn = Zone(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    children: copyOriginalValues
        ? _originalChildren
            .map((child) =>
                child.copyWith(copyOriginalValues: copyOriginalValues))
            .toList()
        : (children ??
            this
                .children
                .map((child) =>
                    child.copyWith(copyOriginalValues: copyOriginalValues))
                .toList()),
    services: services ??
        this
            .services
            .map((service) =>
                service.copyWith(copyOriginalValues: copyOriginalValues))
            .toList(),
    metadata: copyOriginalValues
        ? _originalMetadata.copyWith(copyOriginalValues: copyOriginalValues)
        : (metadata ??
            this.metadata.copyWith(copyOriginalValues: copyOriginalValues)),
  );

  if (copyOriginalValues) {
    toReturn.type = type ?? this.type;
    toReturn.children = children ??
        this
            .children
            .map((child) =>
                child.copyWith(copyOriginalValues: copyOriginalValues))
            .toList();
    toReturn.metadata = metadata ??
        this.metadata.copyWith(copyOriginalValues: copyOriginalValues);
  }

  return toReturn;
}