fromJson static method

AccountLeaderboardSchema? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static AccountLeaderboardSchema? 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(() {
      assert(json.containsKey(r'position'),
          'Required key "AccountLeaderboardSchema[position]" is missing from JSON.');
      assert(json[r'position'] != null,
          'Required key "AccountLeaderboardSchema[position]" has a null value in JSON.');
      assert(json.containsKey(r'account'),
          'Required key "AccountLeaderboardSchema[account]" is missing from JSON.');
      assert(json[r'account'] != null,
          'Required key "AccountLeaderboardSchema[account]" has a null value in JSON.');
      assert(json.containsKey(r'member'),
          'Required key "AccountLeaderboardSchema[member]" is missing from JSON.');
      assert(json[r'member'] != null,
          'Required key "AccountLeaderboardSchema[member]" has a null value in JSON.');
      assert(json.containsKey(r'achievements_points'),
          'Required key "AccountLeaderboardSchema[achievements_points]" is missing from JSON.');
      assert(json[r'achievements_points'] != null,
          'Required key "AccountLeaderboardSchema[achievements_points]" has a null value in JSON.');
      assert(json.containsKey(r'gold'),
          'Required key "AccountLeaderboardSchema[gold]" is missing from JSON.');
      assert(json[r'gold'] != null,
          'Required key "AccountLeaderboardSchema[gold]" has a null value in JSON.');
      return true;
    }());

    return AccountLeaderboardSchema(
      position: mapValueOfType<int>(json, r'position')!,
      account: mapValueOfType<String>(json, r'account')!,
      member: mapValueOfType<bool>(json, r'member')!,
      achievementsPoints: mapValueOfType<int>(json, r'achievements_points')!,
      completedAt: mapDateTime(json, r'completed_at', r''),
      gold: mapValueOfType<int>(json, r'gold')!,
    );
  }
  return null;
}