fromJson static method

AttachmentAction fromJson(
  1. dynamic json
)

Create a specific AttachmentAction from a json file

Implementation

static AttachmentAction fromJson(dynamic json) {
  final type = _AttachmentActionType.values.firstWhere(
    (e) => e.name == json['type'],
    orElse: () => throw ArgumentError.value(
      json['type'],
      'Unknown AttachmentActionType ${json['type']}',
    ),
  );
  final attachment = Attachment.fromJson(json['attachment']);
  return switch (type) {
    _AttachmentActionType.add => AddAttachmentAction(
        byteData: json['byteData'] != null
            ? Uint8List.fromList(json['byteData'].cast<int>())
            : null,
        path: json['path'],
        attachment: attachment,
      ),
    _AttachmentActionType.delete =>
      DeleteAttachmentAction(attachment: attachment),
    _AttachmentActionType.rename => RenameAttachmentAction(
        newName: json['newName'],
        attachment: attachment,
      ),
  };
}