Files
packet/lib/domain/entities/archivo_adjunto.dart

34 lines
771 B
Dart
Raw Permalink Normal View History

import 'dart:typed_data';
enum ArchivoTipo { image, audio, video, document }
class ArchivoAdjunto {
final String nombre;
final String mimeType;
final Uint8List bytes;
final ArchivoTipo tipo;
final String? hash;
ArchivoAdjunto({
required this.nombre,
required this.mimeType,
required this.bytes,
required this.tipo,
this.hash,
});
Map<String, dynamic> toJson() => {
'nombre': nombre,
'tipo': mimeType,
'contenido': bytes,
};
int get sizeBytes => bytes.length;
String get sizeFormatted {
if (sizeBytes < 1024) return '$sizeBytes B';
if (sizeBytes < 1024 * 1024) return '${(sizeBytes / 1024).toStringAsFixed(1)} KB';
return '${(sizeBytes / (1024 * 1024)).toStringAsFixed(1)} MB';
}
}