ReviewComment.fromJson constructor

ReviewComment.fromJson(
  1. Map<String, Object?> json
)

Implementation

factory ReviewComment.fromJson(Map<String, Object?> json) {
  Map<String, double>? parsedRect;
  if (json['rectPct'] case final Map<Object?, Object?> rawRect) {
    final mapped = <String, double>{};
    for (final entry in rawRect.entries) {
      if (entry.key is String && entry.value is num) {
        mapped[entry.key as String] = (entry.value as num).toDouble();
      }
    }
    if (mapped.isNotEmpty) {
      parsedRect = mapped;
    }
  }

  return ReviewComment(
    id: _asString(json['id']),
    site: _asString(json['site']),
    pageUrl: _asString(json['pageUrl'], fallback: '/'),
    pageTitle: _asString(json['pageTitle']),
    sourceFile: _asString(json['sourceFile']),
    resolvedFile: _asString(json['resolvedFile']),
    startLine: _asIntOrNull(json['startLine']),
    endLine: _asIntOrNull(json['endLine']),
    codeSnippet: _asNullableString(json['codeSnippet']),
    anchorType: _asString(json['anchorType'], fallback: 'text'),
    selectedText: _asString(json['selectedText']),
    prefixContext: _asString(json['prefixContext']),
    suffixContext: _asString(json['suffixContext']),
    selector: _asString(json['selector']),
    elementTag: _asString(json['elementTag']),
    elementText: _asString(json['elementText']),
    headingAnchor: _asString(json['headingAnchor']),
    rectPct: parsedRect,
    comment: _asString(json['comment']),
    author: _asString(json['author'], fallback: 'local'),
    status: _asString(json['status'], fallback: 'open') == 'resolved'
        ? 'resolved'
        : 'open',
    createdAt: _asString(json['createdAt']),
    updatedAt: _asString(json['updatedAt']),
  );
}