fromJson static method
Poll?
fromJson(
- dynamic value
)
Returns a new Poll instance and imports its values from
value
if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Poll? 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 "Poll[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "Poll[$key]" has a null value in JSON.');
});
return true;
}());
return Poll(
custom: mapCastOfType<String, Object>(json, r'Custom')!,
allowAnswers: mapValueOfType<bool>(json, r'allow_answers')!,
allowUserSuggestedOptions: mapValueOfType<bool>(json, r'allow_user_suggested_options')!,
answersCount: mapValueOfType<int>(json, r'answers_count')!,
createdAt: mapDateTime(json, r'created_at', r'')!,
createdBy: UserObject.fromJson(json[r'created_by']),
createdById: mapValueOfType<String>(json, r'created_by_id')!,
description: mapValueOfType<String>(json, r'description')!,
enforceUniqueVote: mapValueOfType<bool>(json, r'enforce_unique_vote')!,
id: mapValueOfType<String>(json, r'id')!,
isClosed: mapValueOfType<bool>(json, r'is_closed'),
latestAnswers: PollVote.listFromJson(json[r'latest_answers']),
latestVotesByOption: json[r'latest_votes_by_option'] == null
? const {}
: PollVote.mapListFromJson(json[r'latest_votes_by_option']),
maxVotesAllowed: mapValueOfType<int>(json, r'max_votes_allowed'),
name: mapValueOfType<String>(json, r'name')!,
options: PollOption.listFromJson(json[r'options']),
ownVotes: PollVote.listFromJson(json[r'own_votes']),
updatedAt: mapDateTime(json, r'updated_at', r'')!,
voteCount: mapValueOfType<int>(json, r'vote_count')!,
voteCountsByOption: mapCastOfType<String, int>(json, r'vote_counts_by_option')!,
votingVisibility: mapValueOfType<String>(json, r'voting_visibility'),
);
}
return null;
}