Skip to content

Instantly share code, notes, and snippets.

@skyjur
Created July 26, 2019 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyjur/602b62e9a24a743af8c0631b99fc0574 to your computer and use it in GitHub Desktop.
Save skyjur/602b62e9a24a743af8c0631b99fc0574 to your computer and use it in GitHub Desktop.
updating final values
void main() {
final order1 = Order(
address: Address(
street: "Daguan",
city: "Taipei",
postcode: "231",
country: "Taiwan"
),
person: Person(
firstName: "Chloe",
lastName: "Hsu"
)
);
final order2 = order1.update(
address: order1.address.update(
street: "Shida",
postcode: "106"
)
);
}
class Order {
final Address address;
final Person person;
Order({this.address, this.person});
update({Address address, Person person}) =>
Order(
address: address ?? this.address,
person: person ?? this.person
);
}
class Address {
final String street;
final String city;
final String postcode;
final String country;
Address({this.street, this.city, this.postcode, this.country});
update({String street, String city, String postcode, String country}) =>
Address(
street: street ?? this.street,
city: city ?? this.city,
postcode: postcode ?? this.postcode,
country: country ?? this.country
);
}
class Person {
final String firstName;
final String lastName;
Person({this.firstName, this.lastName});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment