4. Modifications

You can use the auto generated builder to modify serializable classes easily!

 var built = person.rebuild((builder) => builder
   ..name = "Günter"
   ..age = 25
 ); // Returns a new instance with changed name and age

Instead of the lamda approach, you can also create a builder instance by calling toBuilder on an object with builder capabilities and later instantiate the new object by calling build.

var builder = person.toBuilder();
builder.name = "Günter";
builder.age = 25;
var obj = builder.build(); // Returns a new instance with changed name and age 

You have run run the code generation to generate and regenerate builders. They are not generated for bean-type models, consider mutating the fields for those classes.

Models can also be cloned and modified using the copy methods on DogEngine.

var person = Person([...]);
var cloned = dogs.copy<Person>(person); // Creates a copy of the object
var modified = dogs.copy<Person>(person, {
    "name": "Alex"
}); // Creates a modified copy of the object with the field "name" set to "Alex"

Last updated