CopyWith
In addition to the copyWith
method of each case-modddel, the super-sealed class has a copyWith
method too. However, this method only includes shared properties that have the same type across all case-modddels.
For example : Let's say we have a Weather
MultiValueObject union :
// @Modddel (... , sharedProps: [ SharedProp('int', 'temperature') ])
// class ... {
factory Weather.sunny({
required int temperature,
}) // { ... }
factory Weather.rainy({
required int temperature,
required double rainIntensity,
}) // { ... }
In this example, temperature
is a shared property of type int
, and it has the same type int
in both case-modddels. So it can be used in the super-sealed class's copyWith
method :
final otherWeather = weather.copyWith(temperature: 12);
Last updated