copyWith method

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

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

  if (copyOriginalValues) {
    toReturn.type = type ?? this.type;
  }

  return toReturn;
}