fromJson static method

Dataset? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static Dataset? 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(() {
      return true;
    }());

    return Dataset(
      id: mapValueOfType<String>(json, r'id'),
      author: mapValueOfType<String>(json, r'author'),
      slug: mapValueOfType<String>(json, r'slug'),
      category: mapValueOfType<String>(json, r'category'),
      license: mapValueOfType<String>(json, r'license'),
      language: mapValueOfType<String>(json, r'language'),
      downloads: mapValueOfType<int>(json, r'downloads'),
      downloadsAll: mapValueOfType<int>(json, r'downloads_all'),
      likes: mapValueOfType<int>(json, r'likes'),
      trendingScore: mapValueOfType<int>(json, r'trending_score'),
      gated: mapValueOfType<int>(json, r'gated'),
      mainSizeBytes: mapValueOfType<int>(json, r'main_size_bytes'),
      sizeDisplay: mapValueOfType<String>(json, r'size_display'),
      ageDays: mapValueOfType<int>(json, r'age_days'),
      isTrending: mapValueOfType<int>(json, r'is_trending'),
      justAdded: mapValueOfType<int>(json, r'just_added'),
      description: mapValueOfType<String>(json, r'description'),
      tags: json[r'tags'] is Iterable
          ? (json[r'tags'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      hfUrl: mapValueOfType<String>(json, r'hf_url'),
      createdAt: mapValueOfType<String>(json, r'created_at'),
      lastModifiedAt: mapValueOfType<String>(json, r'last_modified_at'),
      firstSeenAt: mapValueOfType<String>(json, r'first_seen_at'),
    );
  }
  return null;
}