Created
July 26, 2019 02:27
-
-
Save skyjur/602b62e9a24a743af8c0631b99fc0574 to your computer and use it in GitHub Desktop.
updating final values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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