fromJson static method

Track? fromJson(
  1. dynamic value
)

Returns a new Track instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static Track? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "Track[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "Track[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return Track(
      trackId: mapValueOfType<int>(json, r'TrackId'),
      name: mapValueOfType<String>(json, r'Name')!,
      audioFile: mapValueOfType<String>(json, r'AudioFile')!,
      imageFile: mapValueOfType<String>(json, r'ImageFile'),
      isrc: mapValueOfType<String>(json, r'Isrc'),
      rating: mapValueOfType<double>(json, r'Rating'),
      title: mapValueOfType<String>(json, r'Title'),
      artist: mapValueOfType<String>(json, r'Artist'),
      album: mapValueOfType<String>(json, r'Album'),
      year: mapValueOfType<int>(json, r'Year'),
      duration: SelectionDuration.fromJson(json[r'Duration']),
      publication: mapValueOfType<bool>(json, r'Publication'),
      reTag: mapValueOfType<bool>(json, r'ReTag'),
      rePeak: mapValueOfType<bool>(json, r'RePeak'),
      invalid: mapValueOfType<bool>(json, r'Invalid'),
      cancel: mapValueOfType<bool>(json, r'Cancel'),
      cancelDate: mapDateTime(json, r'CancelDate', ''),
      newest: mapValueOfType<bool>(json, r'Newest'),
      status: TrackStatus.fromJson(json[r'Status']),
      oldAudioFile: mapValueOfType<String>(json, r'OldAudioFile'),
      createDate: mapDateTime(json, r'CreateDate', ''),
      changeDate: mapDateTime(json, r'ChangeDate', ''),
      copyRightOwnerId: mapValueOfType<int>(json, r'CopyRightOwnerId'),
      copyRightOwner: ApplicationUserCopyRightOwner.fromJson(json[r'CopyRightOwner']),
      rawTags: mapValueOfType<String>(json, r'RawTags'),
      fileHash: mapValueOfType<String>(json, r'FileHash'),
      companyTypeTracks: CompanyTypeTrack.listFromJson(json[r'CompanyTypeTracks']) ?? const [],
      genreTracks: GenreTrack.listFromJson(json[r'GenreTracks']) ?? const [],
      trackSelections: TrackSelection.listFromJson(json[r'TrackSelections']) ?? const [],
      trackPlayLists: TrackPlayList.listFromJson(json[r'TrackPlayLists']) ?? const [],
    );
  }
  return null;
}