@@ -36,17 +36,34 @@ class ServiceFilesBloc extends Bloc<ServiceFilesEvent, ServiceFilesState> {
|
||||
ServiceSavedEvent event,
|
||||
Emitter<ServiceFilesState> emit,
|
||||
) {
|
||||
emit(state.copyWith(serviceId: event.serviceId));
|
||||
// 1. Aggiorniamo l'ID nello stato
|
||||
// 2. PIALLIAMO i file locali: ormai sono partiti per Supabase!
|
||||
// Così la UI si pulisce all'istante e aspetta quelli remoti.
|
||||
emit(
|
||||
state.copyWith(
|
||||
serviceId: event.serviceId,
|
||||
localFiles: [], // <-- LA MAGIA ANTI-DUPLICATI
|
||||
),
|
||||
);
|
||||
|
||||
// Lanciamo il caricamento
|
||||
add(LoadServiceFilesEvent(serviceId: event.serviceId));
|
||||
}
|
||||
|
||||
FutureOr<void> _onLoadServiceFiles(
|
||||
LoadServiceFilesEvent event,
|
||||
Emitter<ServiceFilesState> emit,
|
||||
) async {
|
||||
if (serviceId != null) {
|
||||
// Usiamo l'ID dell'evento, e se non c'è usiamo quello dello stato
|
||||
final currentId = event.serviceId ?? state.serviceId;
|
||||
|
||||
if (currentId != null) {
|
||||
emit(state.copyWith(status: ServiceFilesStatus.loading));
|
||||
|
||||
await emit.forEach(
|
||||
_repository.getServiceFilesStream(serviceId!),
|
||||
_repository.getServiceFilesStream(
|
||||
currentId,
|
||||
), // <-- Usiamo l'ID corretto!
|
||||
onData: (data) => state.copyWith(
|
||||
status: ServiceFilesStatus.success,
|
||||
remoteFiles: data,
|
||||
|
||||
Reference in New Issue
Block a user