copyWith method

Matter copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. int? maxFabrics,
  5. bool? hasQrCode,
  6. String? action = "",
  7. bool copyOriginalValues = true,
})

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

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

Matter copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  int? maxFabrics,
  bool? hasQrCode,
  String? action = "",
  bool copyOriginalValues = true,
}) {
  Matter toReturn = Matter(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    maxFabrics: maxFabrics ?? this.maxFabrics,
    hasQrCode: hasQrCode ?? this.hasQrCode,
    action: copyOriginalValues
        ? _originalAction
        : (action == null || action.isNotEmpty ? action : this.action),
  );

  if (copyOriginalValues) {
    toReturn.type = type ?? this.type;
    toReturn.action =
        action == null || action.isNotEmpty ? action : this.action;
  }

  return toReturn;
}