fg
This commit is contained in:
@@ -8,7 +8,7 @@ import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
|
||||
class AttachmentsRepository {
|
||||
final _supabase = Supabase.instance.client;
|
||||
static const String _bucketName = 'attachments';
|
||||
static const String _bucketName = 'documents';
|
||||
static const String _tableName =
|
||||
'attachment'; // Cambia col vero nome della tua tabella se diverso!
|
||||
|
||||
|
||||
@@ -186,4 +186,32 @@ class TicketFormCubit extends Cubit<TicketFormState> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 5.1 SALVATAGGIO SILENZIOSO (Per generare il QR Code al volo)
|
||||
Future<String?> saveTicketDraft() async {
|
||||
// Non mettiamo lo stato 'saving' per non far sfarfallare tutta la UI,
|
||||
// usiamo un caricamento invisibile.
|
||||
try {
|
||||
final ticketToSave = state.ticket;
|
||||
|
||||
if (ticketToSave.customerId == null || ticketToSave.customerId!.isEmpty) {
|
||||
throw Exception("Seleziona un cliente prima di poter usare il QR.");
|
||||
}
|
||||
|
||||
final savedTicket = await _repository.saveTicket(ticketToSave);
|
||||
|
||||
// Aggiorniamo silenziosamente lo stato con il ticket che ora ha un ID!
|
||||
emit(state.copyWith(ticket: savedTicket, status: TicketFormStatus.ready));
|
||||
|
||||
return savedTicket.id;
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: TicketFormStatus.failure,
|
||||
errorMessage: e.toString(),
|
||||
),
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/customer_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/model_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/shared_files_section.dart';
|
||||
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||
import 'package:flux/features/tickets/blocs/ticket_form_cubit.dart';
|
||||
import 'package:flux/features/tickets/blocs/ticket_form_state.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_model.dart';
|
||||
@@ -99,6 +100,25 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> _generateIdForQr() async {
|
||||
// 1. Validiamo i campi obbligatori (es. il cliente)
|
||||
if (!_formKey.currentState!.validate()) return null;
|
||||
|
||||
// 2. Sincronizziamo i testi scritti a mano nel Cubit
|
||||
_flushControllersToCubit();
|
||||
|
||||
// 3. Facciamo il salvataggio silenzioso
|
||||
final newId = await context.read<TicketFormCubit>().saveTicketDraft();
|
||||
|
||||
if (newId != null && context.mounted) {
|
||||
// 4. IL TOCCO DI CLASSE: Diciamo all'AttachmentsBloc che ora la pratica ha un ID!
|
||||
// Questo farà partire l'upload automatico di eventuali file "in bozza"
|
||||
context.read<AttachmentsBloc>().add(ParentEntitySavedEvent(newId));
|
||||
}
|
||||
|
||||
return newId;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
@@ -514,7 +534,12 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
// ECCO LA MAGIA:
|
||||
SharedFilesSection(
|
||||
titleNameForUpload: ticket.customerName ?? 'Nuovo Ticket',
|
||||
onGenerateIdForQr: _generateIdForQr,
|
||||
),
|
||||
/* SharedAttachmentsSection(
|
||||
parentType: AttachmentParentType.ticket,
|
||||
parentId: ticket.id,
|
||||
), */
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user