StampAnnotation.fromJson constructor
StampAnnotation.fromJson(
- Map<String, dynamic> json
)
Implementation
factory StampAnnotation.fromJson(Map<String, dynamic> json) {
// Handle attachment - can be either a string (existing format) or an object (from native getAnnotations)
String? attachmentData;
if (json['attachment'] is String) {
attachmentData = json['attachment'] as String;
} else if (json['attachment'] is Map) {
// Extract binary data from the attachment object
// Use Map.from to handle platform channel maps (_Map<Object?, Object?>)
final attachmentObj =
Map<String, dynamic>.from(json['attachment'] as Map);
attachmentData = attachmentObj['binary'] as String?;
}
return StampAnnotation(
id: json['id'] as String?,
bbox: Annotation._toDoubleList(json['bbox'] as List),
createdAt: json['createdAt'] as String?,
creatorName: json['creatorName'] as String?,
stampType: StampType.values.firstWhere(
(e) => e.name == json['stampType'] as String,
orElse: () => StampType.approved,
),
attachment: attachmentData,
rotation: (json['rotation'] as num?)?.toDouble() ?? 0.0,
title: json['title'] as String?,
color: Annotation._hexToColor(json['color'] as String?),
subtitle: json['subtitle'] 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,
customData: json['customData'] != null
? Map<String, dynamic>.from(json['customData'])
: null,
);
}