I came across the following code example from flutter_redux example code. Had a hard time to understand why factory SearchState.initial()
returns with a new
keyword while factory SearchState.loading()
and factory SearchState.error()
don't.
class SearchState {
final SearchResult result;
final bool hasError;
final bool isLoading;
SearchState({
this.result,
this.hasError = false,
this.isLoading = false,
});
factory SearchState.initial() =>
new SearchState(result: SearchResult.noTerm());
factory SearchState.loading() => SearchState(isLoading: true);
factory SearchState.error() => SearchState(hasError: true);
}
Just found the Dart language tour not very helpful to this case, and the Dart language specification is too obscure.