How to take advantage of the cascade operator
So far, you’ve seen how Dart follows many of the same patterns of other modern languages. Dart, in some ways, takes the best ideas from multiple languages – you have the expressiveness of JavaScript and the type safety of Java.
However, there are some features that are unique to Dart. One of those features is the cascade (..) operator.
Getting ready
Before we dive into the code, let's diverge briefly to the builder pattern. Builders are a type of class whose only purpose is to build other classes. They are often used for complex objects with many properties. It can get to a point where standard constructors become impractical and unwieldy because they are too large. This is the problem the builder pattern solves. It is a special kind of class whose only job is to configure and create other classes.
This is how we would accomplish the builder pattern without the cascade operator:
class UrlBuilder {
String _scheme;
String...