Proposal.fromJson constructor

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

Implementation

factory Proposal.fromJson(Map<String, dynamic> json) {
  // Handle totalVotes as either string or number
  String totalVotesStr;
  final totalVotesValue = json['total_votes'];
  if (totalVotesValue is String) {
    totalVotesStr = totalVotesValue;
  } else if (totalVotesValue is num) {
    totalVotesStr = totalVotesValue.toString();
  } else {
    totalVotesStr = '0';
  }

  return Proposal(
    id: json['id'] is int ? json['id'] : int.parse(json['id'].toString()),
    proposalId: json['proposal_id'] is int ? json['proposal_id'] : int.parse(json['proposal_id'].toString()),
    creator: json['creator'].toString(),
    receiver: json['receiver'].toString(),
    permlink: json['permlink'].toString(),
    subject: json['subject'].toString(),
    status: json['status'].toString(),
    startDate: json['start_date'].toString(),
    endDate: json['end_date'].toString(),
    totalVotes: totalVotesStr,
    dailyPay: ProposalAsset.fromJson(json['daily_pay']),
  );
}