Discussion.fromJson constructor
Discussion.fromJson(
- Map<String, dynamic> json
)
Implementation
factory Discussion.fromJson(Map<String, dynamic> json) {
final metadataRaw = json['json_metadata'];
final statsRaw = json['stats'];
Stats? stats;
JsonMetadata? metadata;
if(statsRaw != null) {
try {
final decoded =
statsRaw is String ? jsonDecode(statsRaw) : statsRaw;
stats = Stats.fromJson(decoded);
} catch (e) {
stats = null;
}
}
if (metadataRaw != null) {
try {
final decoded =
metadataRaw is String ? jsonDecode(metadataRaw) : metadataRaw;
metadata = JsonMetadata.fromJson(decoded);
} catch (e) {
metadata = null;
}
}
return Discussion(
id: json['id'],
category: json['category'],
parentAuthor: json['parent_author'],
parentPermlink: json['parent_permlink'],
author: json['author'],
permlink: json['permlink'],
title: json['title'],
body: json['body'],
jsonMetadata: metadata,
stats: stats,
lastUpdate: json['last_update'],
created: json['created'],
active: json['active'],
lastPayout: json['last_payout'],
depth: json['depth'],
children: json['children'],
netRshares: json['net_rshares'],
absRshares: json['abs_rshares'],
voteRshares: json['vote_rshares'],
childrenAbsRshares: json['children_abs_rshares'],
cashoutTime: json['cashout_time'],
maxCashoutTime: json['max_cashout_time'],
totalVoteWeight: json['total_vote_weight'],
rewardWeight: json['reward_weight'],
totalPayoutValue:
json['total_payout_value'] != null
? DiscussionAsset.fromJson(json['total_payout_value'])
: null,
curatorPayoutValue:
json['curator_payout_value'] != null
? DiscussionAsset.fromJson(json['curator_payout_value'])
: null,
authorRewards: json['author_rewards'],
netVotes: json['net_votes'],
rootComment: json['root_comment'],
maxAcceptedPayout: json['max_accepted_payout'],
percentHbd: json['percent_hbd'],
allowReplies: json['allow_replies'],
allowVotes: json['allow_votes'],
allowCurationRewards: json['allow_curation_rewards'],
beneficiaries:
json['beneficiaries'] != null
? List<BeneficiaryRoute>.from(
json['beneficiaries'].map((x) => BeneficiaryRoute.fromJson(x)),
)
: null,
url: json['url'],
rootTitle: json['root_title'],
payout: json['payout'] != null ? (json['payout'] as num).toDouble() : null,
payoutAt: json['payout_at'],
pendingPayoutValue:
json['pending_payout_value'] != null
? DiscussionAsset.fromJson(json['pending_payout_value'])
: null,
totalPendingPayoutValue:
json['total_pending_payout_value'] != null
? DiscussionAsset.fromJson(json['total_pending_payout_value'])
: null,
activeVotes:
json['active_votes'] != null
? List<ActiveVote>.from(
json['active_votes'].map((x) => ActiveVote.fromJson(x)),
)
: null,
replies:
json['replies'] != null ? List<String>.from(json['replies']) : null,
authorReputation: json['author_reputation'],
promoted:
json['promoted'] != null ? DiscussionAsset.fromJson(json['promoted']) : null,
rebloggedBy:
json['reblogged_by'] != null
? List<String>.from(json['reblogged_by'])
: null,
firstRebloggedBy: json['first_reblogged_by'],
firstRebloggedOn: json['first_reblogged_on'],
community: json['community'] ?? '',
communityTitle: json['community_title'] ?? '',
);
}