我从flutter_redux示例代码中遇到了以下代码示例。很难理解为什么factory SearchState.initial()new关键字返回而factory SearchState.loading()factory SearchState.error()没有返回。

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);
}

刚刚发现Dart语言之旅对这种情况不是很有帮助,而且Dart语言规范过于晦涩。

最佳答案

effective dart指南中的引语:

10-06 14:30