fix attachments
All checks were successful
Build and Release FLUX (Multi-Platform) / build-android (push) Successful in 1m44s
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 1m5s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 8m7s

This commit is contained in:
2026-06-08 14:36:31 +02:00
parent 22bb86f052
commit f8504d466a
3 changed files with 28 additions and 13 deletions

View File

@@ -26,6 +26,9 @@ class OperationFormScreen extends StatefulWidget {
class _OperationFormScreenState extends State<OperationFormScreen> {
final _formKey = GlobalKey<FormState>();
// 🥷 IL NUOVO FLAG: Ci ricorderà se vogliamo davvero uscire!
bool _isClosingIntent = false;
final _referenceController = TextEditingController();
final _noteController = TextEditingController();
final _freeTextSubtypeController = TextEditingController();
@@ -101,10 +104,11 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
required bool keepAdding,
}) {
if (_formKey.currentState!.validate()) {
// Se non stiamo facendo "Salva e Aggiungi Altro", il nostro intento è chiudere
_isClosingIntent = !keepAdding;
_flushControllersToCubit();
// Aggiorniamo prima lo stato bersaglio nel cubit
context.read<OperationFormCubit>().updateFields(status: targetStatus);
// Poi chiamiamo il salvataggio
context.read<OperationFormCubit>().saveOperation(
targetStatus: targetStatus,
keepAdding: keepAdding,
@@ -112,11 +116,15 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
}
}
Future<String?> _generateIdForQr() async {
// RINOMINATA E RESA SICURA
Future<String?> _ensureEntitySaved() async {
if (!_formKey.currentState!.validate()) return null;
// 🥷 Diciamo esplicitamente al sistema che NON vogliamo uscire dalla pagina
_isClosingIntent = false;
_flushControllersToCubit();
// Lo leggiamo pulito pulito dal context, perché c'è!
final attachmentsBloc = context.read<AttachmentsBloc>();
final newId = await context.read<OperationFormCubit>().saveOperationDraft();
@@ -151,8 +159,15 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
if (state.status == OperationFormStatus.ready && !_isInitialized) {
_syncTextControllers(state.operation);
}
// 🥷 ORA POPPA SOLO SE L'INTENTO ERA QUELLO DI USCIRE!
if (state.status == OperationFormStatus.success) {
Navigator.of(context).pop();
if (_isClosingIntent) {
Navigator.of(context).pop();
} else {
// È stato un salvataggio background (Pick Files o QR).
// Non facciamo nulla, l'utente resta sulla pagina e i file vengono caricati!
}
} else if (state.status == OperationFormStatus.successAndAddAnother) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
@@ -626,7 +641,7 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
parentType: AttachmentParentType.operation,
parentId: state.operation.id,
titleForUpload: state.operation.customer?.name ?? 'Nuova Pratica',
onGenerateIdForQr: _generateIdForQr,
onEnsureEntitySaved: _ensureEntitySaved, // 🥷 Il nuovo nome!
),
],
);