ImageAnnotation.fromJson constructor
ImageAnnotation.fromJson(
- Map<String, dynamic> json, [
- Map<String, dynamic>? attachments
])
Implementation
factory ImageAnnotation.fromJson(Map<String, dynamic> json,
[Map<String, dynamic>? attachments]) {
final String imageAttachmentId = json['imageAttachmentId'] as String? ?? '';
// Parse attachment - first check for inline attachment (from native getAnnotations),
// then fall back to attachments map (from Instant JSON)
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,
);
} else if (attachments != null && imageAttachmentId.isNotEmpty) {
final attachmentData = attachments[imageAttachmentId];
if (attachmentData != null) {
attachment = AnnotationAttachment.fromJson(
imageAttachmentId,
Map<String, dynamic>.from(attachmentData as Map),
);
}
}
return ImageAnnotation(
id: json['id'] as String?,
bbox: Annotation._toDoubleList(json['bbox'] as List),
createdAt: json['createdAt'] as String?,
creatorName: json['creatorName'] as String?,
rotation: (json['rotation'] as num?)?.toDouble() ?? 0.0,
description: json['description'] as String?,
fileName: json['fileName'] as String?,
contentType: json['contentType'] as String?,
imageAttachmentId: imageAttachmentId,
note: json['note'] as String?,
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,
isSignature: json['isSignature'] as bool?,
customData: json['customData'] != null
? Map<String, dynamic>.from(json['customData'])
: null,
attachment: attachment);
}