copyWith method

DiscoveredBridge copyWith({
  1. Object? rawIdFromEndpoint = sentinelValue,
  2. Object? rawIdFromMdns = sentinelValue,
  3. String? ipAddress,
})

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

Since rawIdFromEndpoint and rawIdFromMdns are nullable, they are defaulted to empty objects in this method. If left as empty objects, their current values in this DiscoveredBridge object will be used. This way, if they are null, the program will know that they are intentionally being set to null.

Implementation

DiscoveredBridge copyWith({
  Object? rawIdFromEndpoint = sentinelValue,
  Object? rawIdFromMdns = sentinelValue,
  String? ipAddress,
}) {
  if (!identical(rawIdFromEndpoint, sentinelValue)) {
    assert(
      rawIdFromEndpoint is String?,
      "`rawIdFromEndpoint` must be an `String?` object",
    );
  }
  if (!identical(rawIdFromMdns, sentinelValue)) {
    assert(
      rawIdFromMdns is String?,
      "`rawIdFromMdns` must be an `String?` object",
    );
  }

  return DiscoveredBridge(
    rawIdFromEndpoint: identical(rawIdFromEndpoint, sentinelValue)
        ? this.rawIdFromEndpoint
        : rawIdFromEndpoint as String?,
    rawIdFromMdns: identical(rawIdFromMdns, sentinelValue)
        ? this.rawIdFromMdns
        : rawIdFromMdns as String?,
    ipAddress: ipAddress ?? this.ipAddress,
  );
}