This commit is contained in:
2026-05-01 10:11:44 +02:00
parent 9c8576ada5
commit f8bcac51e1
48 changed files with 1187 additions and 1141 deletions

View File

@@ -0,0 +1,100 @@
import 'dart:typed_data';
import 'package:equatable/equatable.dart';
class OperationFileModel extends Equatable {
final String? id;
final DateTime? createdAt;
final String name;
final String extension;
final String storagePath;
final String operationId;
final int fileSize;
final Uint8List? localBytes;
const OperationFileModel({
this.id,
this.createdAt,
required this.name,
required this.extension,
required this.storagePath,
required this.operationId,
required this.fileSize,
this.localBytes,
});
bool get isLocal => localBytes != null;
// Trasforma i byte in qualcosa di leggibile (KB, MB, GB)
String get sizeFormatted {
if (fileSize <= 0) return "0 B";
const suffixes = ["B", "KB", "MB", "GB", "TB"];
var i = (fileSize.toString().length - 1) ~/ 3;
if (i >= suffixes.length) i = suffixes.length - 1;
double num = fileSize / (1 << (i * 10));
return "${num.toStringAsFixed(i == 0 ? 0 : 1)} ${suffixes[i]}";
}
bool get isPdf => extension.toLowerCase().replaceAll('.', '') == 'pdf';
OperationFileModel copyWith({
String? id,
DateTime? createdAt,
String? name,
String? extension,
String? storagePath,
String? operationId,
int? fileSize,
Uint8List? localBytes,
}) {
return OperationFileModel(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
name: name ?? this.name,
extension: extension ?? this.extension,
storagePath: storagePath ?? this.storagePath,
operationId: operationId ?? this.operationId,
fileSize: fileSize ?? this.fileSize,
localBytes: localBytes ?? this.localBytes,
);
}
factory OperationFileModel.fromMap(Map<String, dynamic> map) {
return OperationFileModel(
id: map['id'] as String,
createdAt: map['created_at'] != null
? DateTime.parse(map['created_at'])
: null,
name: map['name'] ?? '',
extension: map['extension'] ?? '',
storagePath: map['storage_path'] ?? '',
operationId: map['operation_id']?.toString() ?? '',
fileSize: map['file_size'] is int
? map['file_size']
: int.tryParse(map['file_size']?.toString() ?? '0') ?? 0,
);
}
Map<String, dynamic> toMap() {
return {
if (id != null) 'id': id,
'name': name,
'extension': extension,
'storage_path': storagePath,
'operation_id': operationId,
'file_size': fileSize,
};
}
@override
List<Object?> get props => [
id,
createdAt,
name,
extension,
storagePath,
operationId,
fileSize,
localBytes,
];
}