copyWith method
BehaviorInstance
copyWith({
- ResourceType? type,
- String? id,
- String? idV1,
- String? scriptId,
- bool? isEnabled,
- Map<
String, dynamic> ? state, - Map<
String, dynamic> ? configuration, - List<
BehaviorInstanceDependee> ? dependees, - String? status,
- String? lastError,
- String? name,
- String? migratedFrom,
- Map<
String, dynamic> ? trigger = const {}, - bool copyOriginalValues = true,
Returns a copy of this object with its field values replaced by the ones provided to this method.
Since trigger
is nullable, it is defaulted to an empty map in this
method. If left as an empty map, its current value in this
BehaviorInstance 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
BehaviorInstance copyWith({
ResourceType? type,
String? id,
String? idV1,
String? scriptId,
bool? isEnabled,
Map<String, dynamic>? state,
Map<String, dynamic>? configuration,
List<BehaviorInstanceDependee>? dependees,
String? status,
String? lastError,
String? name,
String? migratedFrom,
Map<String, dynamic>? trigger = const {},
bool copyOriginalValues = true,
}) {
BehaviorInstance toReturn = BehaviorInstance(
type: copyOriginalValues ? originalType : (type ?? this.type),
id: id ?? this.id,
idV1: idV1 ?? this.idV1,
scriptId:
copyOriginalValues ? _originalScriptId : (scriptId ?? this.scriptId),
isEnabled: copyOriginalValues
? _originalIsEnabled
: (isEnabled ?? this.isEnabled),
state: state ?? Map<String, dynamic>.from(this.state),
configuration: copyOriginalValues
? Map<String, dynamic>.from(_originalConfiguration)
: (configuration ?? Map<String, dynamic>.from(this.configuration)),
dependees: dependees ??
this.dependees.map((dependee) => dependee.copyWith()).toList(),
status: status ?? this.status,
lastError: lastError ?? this.lastError,
name: copyOriginalValues ? _originalName : (name ?? this.name),
migratedFrom: copyOriginalValues
? _originalMigratedFrom
: (migratedFrom ?? this.migratedFrom),
trigger: copyOriginalValues
? _originalTrigger == null
? null
: Map<String, dynamic>.from(_originalTrigger!)
: (trigger == null || trigger.isNotEmpty
? trigger
: (this.trigger == null
? null
: Map<String, dynamic>.from(this.trigger!))),
);
if (copyOriginalValues) {
toReturn.type = type ?? this.type;
toReturn.scriptId = scriptId ?? this.scriptId;
toReturn.isEnabled = isEnabled ?? this.isEnabled;
toReturn.configuration =
configuration ?? Map<String, dynamic>.from(this.configuration);
toReturn.name = name ?? this.name;
toReturn.migratedFrom = migratedFrom ?? this.migratedFrom;
toReturn.trigger = trigger == null || trigger.isNotEmpty
? trigger
: (this.trigger == null
? null
: Map<String, dynamic>.from(this.trigger!));
}
return toReturn;
}