Annotation.fromJson constructor

Annotation.fromJson(
  1. Map<String, dynamic> json, [
  2. Map<String, dynamic>? attachments
])

Implementation

factory Annotation.fromJson(Map<String, dynamic> json,
    [Map<String, dynamic>? attachments]) {
  final type = AnnotationType.values.firstWhere(
    (e) => e.fullName == json['type'] as String?,
    orElse: () => AnnotationType.undefined,
  );

  switch (type) {
    case AnnotationType.ink:
      return InkAnnotation.fromJson(json);
    case AnnotationType.highlight:
      return HighlightAnnotation.fromJson(json);
    case AnnotationType.note:
      return NoteAnnotation.fromJson(json);
    case AnnotationType.square:
      return SquareAnnotation.fromJson(json);
    case AnnotationType.circle:
      return CircleAnnotation.fromJson(json);
    case AnnotationType.line:
      return LineAnnotation.fromJson(json);
    case AnnotationType.freeText:
      return FreeTextAnnotation.fromJson(json);
    case AnnotationType.stamp:
      return StampAnnotation.fromJson(json);
    case AnnotationType.redact:
      return RedactionAnnotation.fromJson(json);
    case AnnotationType.widget:
      return WidgetAnnotation.fromJson(json);
    case AnnotationType.sound:
      return SoundAnnotation.fromJson(json);
    case AnnotationType.file:
      return FileAnnotation.fromJson(json);
    case AnnotationType.strikeout:
      return StrikeoutAnnotation.fromJson(json);
    case AnnotationType.underline:
      return UnderlineAnnotation.fromJson(json);
    case AnnotationType.squiggly:
      return SquigglyAnnotation.fromJson(json);
    case AnnotationType.link:
      return LinkAnnotation.fromJson(json);
    case AnnotationType.polygon:
      return PolygonAnnotation.fromJson(json);
    case AnnotationType.polyline:
      return PolylineAnnotation.fromJson(json);
    case AnnotationType.popup:
      return PopupAnnotation.fromJson(json);
    case AnnotationType.caret:
      return CaretAnnotation.fromJson(json);
    case AnnotationType.media:
      return RichMediaAnnotation.fromJson(json, attachments);
    case AnnotationType.screen:
      return ScreenAnnotation.fromJson(json);
    case AnnotationType.watermark:
      return WatermarkAnnotation.fromJson(json);
    case AnnotationType.type3d:
      return Type3DAnnotation.fromJson(json);
    case AnnotationType.image:
      return ImageAnnotation.fromJson(
        json,
        attachments,
      );
    default:
      throw UnimplementedError(
          'Annotation type ${type.fullName} is not implemented');
  }
}