fromJson static method

ReviewQueueItem? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static ReviewQueueItem? 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 "ReviewQueueItem[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "ReviewQueueItem[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return ReviewQueueItem(
      actions: ActionLog.listFromJson(json[r'actions']),
      assignedTo: UserObject.fromJson(json[r'assigned_to']),
      bans: Ban.listFromJson(json[r'bans']),
      completedAt: NullTime.fromJson(json[r'completed_at'])!,
      contentChanged: mapValueOfType<bool>(json, r'content_changed')!,
      createdAt: mapDateTime(json, r'created_at', r'')!,
      entityCreator: UserObject.fromJson(json[r'entity_creator']),
      entityId: mapValueOfType<String>(json, r'entity_id')!,
      entityType: mapValueOfType<String>(json, r'entity_type')!,
      feedsV2Activity: EnrichedActivity.fromJson(json[r'feeds_v2_activity']),
      feedsV2Reaction: Reaction.fromJson(json[r'feeds_v2_reaction']),
      flags: Flag2.listFromJson(json[r'flags']),
      hasImage: mapValueOfType<bool>(json, r'has_image')!,
      hasText: mapValueOfType<bool>(json, r'has_text')!,
      hasVideo: mapValueOfType<bool>(json, r'has_video')!,
      id: mapValueOfType<String>(json, r'id')!,
      languages: json[r'languages'] is Iterable
          ? (json[r'languages'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      message: Message.fromJson(json[r'message']),
      moderationPayload: ModerationPayload.fromJson(json[r'moderation_payload']),
      moderationPayloadHash: mapValueOfType<String>(json, r'moderation_payload_hash')!,
      recommendedAction: mapValueOfType<String>(json, r'recommended_action')!,
      reviewedAt: NullTime.fromJson(json[r'reviewed_at'])!,
      reviewedBy: mapValueOfType<String>(json, r'reviewed_by')!,
      severity: mapValueOfType<int>(json, r'severity')!,
      status: mapValueOfType<String>(json, r'status')!,
      updatedAt: mapDateTime(json, r'updated_at', r'')!,
    );
  }
  return null;
}