Attachment constructor

Attachment({
  1. String? id,
  2. String? type,
  3. String? titleLink,
  4. String? title,
  5. String? thumbUrl,
  6. String? text,
  7. String? pretext,
  8. String? ogScrapeUrl,
  9. String? imageUrl,
  10. String? footerIcon,
  11. String? footer,
  12. dynamic fields,
  13. String? fallback,
  14. String? color,
  15. String? authorName,
  16. String? authorLink,
  17. String? authorIcon,
  18. String? assetUrl,
  19. List<Action>? actions,
  20. Map<String, Object?> extraData = const {},
  21. AttachmentFile? file,
  22. UploadState? uploadState,
})

Constructor used for json serialization

Implementation

Attachment({
  String? id,
  this.type,
  this.titleLink,
  String? title,
  this.thumbUrl,
  this.text,
  this.pretext,
  this.ogScrapeUrl,
  this.imageUrl,
  this.footerIcon,
  this.footer,
  this.fields,
  this.fallback,
  this.color,
  this.authorName,
  this.authorLink,
  this.authorIcon,
  this.assetUrl,
  List<Action>? actions,
  Map<String, Object?> extraData = const {},
  this.file,
  UploadState? uploadState,
})  : id = id ?? const Uuid().v4(),
      title = title ?? file?.name,
      localUri = file?.path != null ? Uri.parse(file!.path!) : null,
      actions = actions ?? [],
      // For backwards compatibility,
      // set 'file_size', 'mime_type' in [extraData].
      extraData = {
        ...extraData,
        if (file?.size != null) 'file_size': file?.size,
        if (file?.mimeType != null) 'mime_type': file?.mimeType?.mimeType,
      } {
  this.uploadState = uploadState ??
      ((assetUrl != null || imageUrl != null)
          ? const UploadState.success()
          : const UploadState.preparing());
}