fromJson static method

Poll? fromJson(
  1. Map<String, dynamic>? json
)

Implementation

static Poll? fromJson(Map<String, dynamic>? json) {
  if (json == null) {
    return null;
  }

  return Poll(
    id: int.tryParse((json['id'] as dynamic)?.toString() ?? '') ?? 0,
    question: FormattedText.fromJson(tdMapFromJson(json['question'])),
    options: List<PollOption>.from(
      tdListFromJson(json['options'])
          .map((item) => PollOption.fromJson(tdMapFromJson(item)))
          .whereType<PollOption>(),
    ),
    totalVoterCount: (json['total_voter_count'] as int?) ?? 0,
    recentVoterIds: List<MessageSender>.from(
      tdListFromJson(json['recent_voter_ids'])
          .map((item) => MessageSender.fromJson(tdMapFromJson(item)))
          .whereType<MessageSender>(),
    ),
    canGetVoters: (json['can_get_voters'] as bool?) ?? false,
    canSeeResults: (json['can_see_results'] as bool?) ?? false,
    isAnonymous: (json['is_anonymous'] as bool?) ?? false,
    allowsMultipleAnswers:
        (json['allows_multiple_answers'] as bool?) ?? false,
    allowsRevoting: (json['allows_revoting'] as bool?) ?? false,
    membersOnly: (json['members_only'] as bool?) ?? false,
    countryCodes: List<String>.from(
      tdListFromJson(
        json['country_codes'],
      ).map((item) => (item as dynamic)?.toString() ?? ''),
    ),
    optionOrder: List<int>.from(
      tdListFromJson(
        json['option_order'],
      ).map((item) => int.tryParse((item as dynamic)?.toString() ?? '') ?? 0),
    ),
    type: PollType.fromJson(tdMapFromJson(json['type'])),
    openPeriod: (json['open_period'] as int?) ?? 0,
    closeDate: (json['close_date'] as int?) ?? 0,
    isClosed: (json['is_closed'] as bool?) ?? false,
    voteRestrictionReason: PollVoteRestrictionReason.fromJson(
      tdMapFromJson(json['vote_restriction_reason']),
    ),
  );
}