Dart Cascade notation
In the flutter code, I see a statement line below:
In the flutter code, I see a statement line below:AppStateModel createDefaultValue() => AppStateModel()..loadProducts()
I am not familiar with operation ..
, why here use AppStateModel()..loadProducts()
at first I thought just call the method loadProducts
and set the return value to the caller.
After search the doc of cascade notation, in the documentation says that:
Cascades (..
,?..
) allow you to make a sequence of operations on the same object. In addition to accessing instance members, you can also call instance methods on that same object. This often saves you the step of creating a temporary variable and allows you to write more fluid code.
So the meaning of the statement is returnAppStateModel
and also call the methodloadProducts
.
The statement above is equivalent to the following:AppStateModel createDefaultValue() {
var appStateModel = AppStateModel();
appStateModel.loadProducts();
return appStateModel;
}