trphoenix
2018-10-30 f2dafcc61407aef960ee17b576794b1260e84a08
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import './github_search_api.dart';
import 'package:json_annotation/json_annotation.dart';
 
part 'SearchResult.g.dart';
 
@JsonSerializable()
class SearchResult extends Object with _$SearchResultSerializerMixin {
  final SearchResultKind kind;
  final List<SearchResultItem> items;
 
  SearchResult(this.kind, this.items);
 
  factory SearchResult.noTerm() =>
      new SearchResult(SearchResultKind.noTerm, <SearchResultItem>[]);
 
  factory SearchResult.fromJson(dynamic json) {
    final items = (json as List)
        .cast<Map<String, Object>>()
        .map((Map<String, Object> item) {
      return new SearchResultItem.fromJson(item);
    }).toList();
 
    return new SearchResult(
      items.isEmpty ? SearchResultKind.empty : SearchResultKind.populated,
      items,
    );
  }
 
  bool get isPopulated => kind == SearchResultKind.populated;
 
  bool get isEmpty => kind == SearchResultKind.empty;
 
  bool get isNoTerm => kind == SearchResultKind.noTerm;
}