FileAnnotation.fromJson constructor

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

Creates a FileAnnotation from a JSON map

Implementation

factory FileAnnotation.fromJson(Map<String, dynamic> json) {
  // Parse inline attachment if present (from native getAnnotations)
  AnnotationAttachment? attachment;
  if (json['attachment'] != null) {
    // Use Map.from to handle platform channel maps (_Map<Object?, Object?>)
    final inlineAttachment =
        Map<String, dynamic>.from(json['attachment'] as Map);
    attachment = AnnotationAttachment.fromJson(
      inlineAttachment['id'] as String,
      inlineAttachment,
    );
  }

  return FileAnnotation(
    id: json['id'] as String?,
    bbox: List<double>.from(json['bbox'] as List),
    createdAt: json['createdAt'] as String?,
    creatorName: json['creatorName'] as String?,
    iconName: json['iconName'] != null
        ? FileIconName.values.firstWhere(
            (e) => e.name == json['iconName'] as String,
            orElse: () => FileIconName.pushPin,
          )
        : null,
    embeddedFile: json['embeddedFile'] != null
        ? EmbeddedFile.fromJson(
            Map<String, dynamic>.from(json['embeddedFile'] as Map))
        : null,
    pageIndex: json['pageIndex'] as int,
    opacity:
        json['opacity'] != null ? Annotation._toDouble(json['opacity']) : 1.0,
    pdfObjectId: json['pdfObjectId'] as int?,
    flags: Annotation._stringsToFlags(json['flags'] as List<dynamic>?),
    updatedAt: json['updatedAt'] as String?,
    name: json['name'] as String?,
    subject: json['subject'] as String?,
    hidden: json['hidden'] as bool? ?? false,
    customData: json['customData'] != null
        ? Map<String, dynamic>.from(json['customData'])
        : null,
    attachment: attachment,
  );
}