Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace tip 4 code image
  • Loading branch information
EsteveAguilera committed Nov 9, 2020
commit c039d4b09d132e231358d29e8d0b844b461b6b03
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,51 @@ We can chain method/member calls without returning `this` from **method(), gette

try in [Dartpad](https://dartpad.dartlang.org/290e17306b745ed83b9242653ca55041)

![cascade](assets/04cascadebefore.png)
Before:
```dart
class User {
String name;
int age;

User({this.name = "Foo", this.age = 0});

User withName(String name) {
this.name = name;
return this;
}

User withAge(int age) {
this.age = age;
return this;
}

void printId() => print("$name is $age years old.");
}

main() {
User()
.withAge(27)
.withName("Laxman")
.printId();
}
```

Can be replaced with
```dart
class User {
String name;
int age;

![cascadeafter](assets/04cascadeafter.png)
void printId() => print("$name is $age years old.");
}

main() {
User()
..age = 27
..name = "Laxman"
..printId();
}
```

## Tip 5 : Dart `data class`

Expand Down
Binary file removed assets/04cascadeafter.png
Binary file not shown.
Binary file removed assets/04cascadebefore.png
Binary file not shown.