refactor pesantissimo dei Customer Files
This commit is contained in:
@@ -235,7 +235,7 @@ class ServicesCubit extends Cubit<ServicesState> {
|
||||
serviceId: state.currentService?.id ?? '',
|
||||
name: file.name.fileNameWithoutExtension(),
|
||||
extension: file.name.fileExtension(),
|
||||
url: '',
|
||||
storagePath: '',
|
||||
fileSize: file.size,
|
||||
localBytes: file.bytes,
|
||||
createdAt: DateTime.now(),
|
||||
@@ -295,7 +295,7 @@ class ServicesCubit extends Cubit<ServicesState> {
|
||||
orElse: () => file,
|
||||
);
|
||||
|
||||
if (savedFile.url.isEmpty) {
|
||||
if (savedFile.storagePath.isEmpty) {
|
||||
throw Exception(
|
||||
"Errore: URL del file non trovato dopo il salvataggio.",
|
||||
);
|
||||
|
||||
@@ -159,7 +159,10 @@ class ServicesRepository {
|
||||
final String mimeType = file.extension.toLowerCase() == 'pdf'
|
||||
? 'application/pdf'
|
||||
: 'image/${file.extension}';
|
||||
final fileToSave = file.copyWith(serviceId: newId, url: storagePath);
|
||||
final fileToSave = file.copyWith(
|
||||
serviceId: newId,
|
||||
storagePath: storagePath,
|
||||
);
|
||||
|
||||
// Creiamo una funzione asincrona per caricare file e scrivere nel DB
|
||||
Future<void> uploadAndLink() async {
|
||||
@@ -235,6 +238,15 @@ class ServicesRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ascolta in tempo reale i file caricati per una pratica
|
||||
Stream<List<Map<String, dynamic>>> getServiceFilesStream(String serviceId) {
|
||||
return _supabase
|
||||
.from('service_file')
|
||||
.stream(primaryKey: ['id'])
|
||||
.eq('service_id', serviceId)
|
||||
.order('created_at', ascending: false);
|
||||
}
|
||||
|
||||
Future<void> copyFileToCustomer({
|
||||
required ServiceFileModel file,
|
||||
required String customerId,
|
||||
@@ -242,7 +254,7 @@ class ServicesRepository {
|
||||
CustomerFileModel fileToCopy = CustomerFileModel(
|
||||
customerId: customerId,
|
||||
name: file.name,
|
||||
url: file.url,
|
||||
storagePath: file.storagePath,
|
||||
extension: file.extension,
|
||||
fileSize: file.fileSize,
|
||||
);
|
||||
|
||||
@@ -7,7 +7,7 @@ class ServiceFileModel extends Equatable {
|
||||
final DateTime? createdAt;
|
||||
final String name;
|
||||
final String extension;
|
||||
final String url;
|
||||
final String storagePath;
|
||||
final String serviceId;
|
||||
final int fileSize;
|
||||
final Uint8List? localBytes;
|
||||
@@ -17,7 +17,7 @@ class ServiceFileModel extends Equatable {
|
||||
this.createdAt,
|
||||
required this.name,
|
||||
required this.extension,
|
||||
required this.url,
|
||||
required this.storagePath,
|
||||
required this.serviceId,
|
||||
required this.fileSize,
|
||||
this.localBytes,
|
||||
@@ -40,7 +40,7 @@ class ServiceFileModel extends Equatable {
|
||||
DateTime? createdAt,
|
||||
String? name,
|
||||
String? extension,
|
||||
String? url,
|
||||
String? storagePath,
|
||||
String? serviceId,
|
||||
int? fileSize,
|
||||
Uint8List? localBytes,
|
||||
@@ -50,7 +50,7 @@ class ServiceFileModel extends Equatable {
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
name: name ?? this.name,
|
||||
extension: extension ?? this.extension,
|
||||
url: url ?? this.url,
|
||||
storagePath: storagePath ?? this.storagePath,
|
||||
serviceId: serviceId ?? this.serviceId,
|
||||
fileSize: fileSize ?? this.fileSize,
|
||||
localBytes: localBytes ?? this.localBytes,
|
||||
@@ -65,7 +65,7 @@ class ServiceFileModel extends Equatable {
|
||||
: null,
|
||||
name: map['name'] ?? '',
|
||||
extension: map['extension'] ?? '',
|
||||
url: map['url'] ?? '',
|
||||
storagePath: map['storage_path'] ?? '',
|
||||
serviceId: map['service_id']?.toString() ?? '',
|
||||
fileSize: map['file_size'] is int
|
||||
? map['file_size']
|
||||
@@ -78,7 +78,7 @@ class ServiceFileModel extends Equatable {
|
||||
if (id != null) 'id': id,
|
||||
'name': name,
|
||||
'extension': extension,
|
||||
'url': url,
|
||||
'storage_path': storagePath,
|
||||
'service_id': serviceId,
|
||||
'file_size': fileSize,
|
||||
};
|
||||
@@ -90,7 +90,7 @@ class ServiceFileModel extends Equatable {
|
||||
createdAt,
|
||||
name,
|
||||
extension,
|
||||
url,
|
||||
storagePath,
|
||||
serviceId,
|
||||
fileSize,
|
||||
localBytes,
|
||||
|
||||
@@ -169,11 +169,15 @@ class AttachmentsSection extends StatelessWidget {
|
||||
height: MediaQuery.of(context).size.height * 0.8,
|
||||
child: file.isPdf
|
||||
? PdfViewerWidget(
|
||||
storagePath: file.url.isNotEmpty ? file.url : null,
|
||||
storagePath: file.storagePath.isNotEmpty
|
||||
? file.storagePath
|
||||
: null,
|
||||
bytes: file.localBytes,
|
||||
)
|
||||
: ImageViewerWidget(
|
||||
storagePath: file.url.isNotEmpty ? file.url : null,
|
||||
storagePath: file.storagePath.isNotEmpty
|
||||
? file.storagePath
|
||||
: null,
|
||||
bytes: file.localBytes,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user