1 Commits

Author SHA1 Message Date
f8504d466a 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
2026-06-08 14:36:31 +02:00
3 changed files with 28 additions and 13 deletions

View File

@@ -34,14 +34,14 @@ class SharedAttachmentsSection extends StatefulWidget {
final String? parentId;
final String titleForUpload;
final AttachmentParentType parentType;
final Future<String?> Function()? onGenerateIdForQr;
final Future<String?> Function()? onEnsureEntitySaved;
const SharedAttachmentsSection({
super.key,
this.parentId,
this.titleForUpload = 'Cliente_sconosciuto',
required this.parentType,
this.onGenerateIdForQr,
this.onEnsureEntitySaved,
});
@override
@@ -95,7 +95,7 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
// 🥷 SE L'ID NON C'È (Nuova Operazione), FORZIAMO IL SALVATAGGIO PREVENTIVO!
if (targetId == null || targetId.isEmpty) {
if (widget.onGenerateIdForQr != null) {
if (widget.onEnsureEntitySaved != null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Salvataggio rapido scheda per allegati... ⏳'),
@@ -104,7 +104,7 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
);
// Chiamiamo la funzione passata dal TicketForm/OperationForm
targetId = await widget.onGenerateIdForQr!();
targetId = await widget.onEnsureEntitySaved!();
}
// Se il salvataggio fallisce (es. form non valido), ci fermiamo per evitare file orfani
@@ -507,7 +507,7 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
// SE L'ID NON C'È, CHIAMIAMO IL SALVATAGGIO IN BACKGROUND!
if (targetId == null) {
if (widget.onGenerateIdForQr != null) {
if (widget.onEnsureEntitySaved != null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
@@ -518,7 +518,7 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
);
// Aspettiamo che il TicketFormCubit faccia il suo lavoro
targetId = await widget.onGenerateIdForQr!();
targetId = await widget.onEnsureEntitySaved!();
}
// Se fallisce (es. validazione form non passata), ci fermiamo

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) {
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!
),
],
);

View File

@@ -1,7 +1,7 @@
name: flux
description: "Gestione attività negozio di telefonia"
publish_to: 'none'
version: 1.1.21+39
version: 1.1.22+40
environment:
sdk: ^3.11.3