Compare commits
1 Commits
22bb86f052
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f8504d466a |
@@ -34,14 +34,14 @@ class SharedAttachmentsSection extends StatefulWidget {
|
|||||||
final String? parentId;
|
final String? parentId;
|
||||||
final String titleForUpload;
|
final String titleForUpload;
|
||||||
final AttachmentParentType parentType;
|
final AttachmentParentType parentType;
|
||||||
final Future<String?> Function()? onGenerateIdForQr;
|
final Future<String?> Function()? onEnsureEntitySaved;
|
||||||
|
|
||||||
const SharedAttachmentsSection({
|
const SharedAttachmentsSection({
|
||||||
super.key,
|
super.key,
|
||||||
this.parentId,
|
this.parentId,
|
||||||
this.titleForUpload = 'Cliente_sconosciuto',
|
this.titleForUpload = 'Cliente_sconosciuto',
|
||||||
required this.parentType,
|
required this.parentType,
|
||||||
this.onGenerateIdForQr,
|
this.onEnsureEntitySaved,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -95,7 +95,7 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
|
|||||||
|
|
||||||
// 🥷 SE L'ID NON C'È (Nuova Operazione), FORZIAMO IL SALVATAGGIO PREVENTIVO!
|
// 🥷 SE L'ID NON C'È (Nuova Operazione), FORZIAMO IL SALVATAGGIO PREVENTIVO!
|
||||||
if (targetId == null || targetId.isEmpty) {
|
if (targetId == null || targetId.isEmpty) {
|
||||||
if (widget.onGenerateIdForQr != null) {
|
if (widget.onEnsureEntitySaved != null) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
content: Text('Salvataggio rapido scheda per allegati... ⏳'),
|
content: Text('Salvataggio rapido scheda per allegati... ⏳'),
|
||||||
@@ -104,7 +104,7 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Chiamiamo la funzione passata dal TicketForm/OperationForm
|
// 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
|
// 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!
|
// SE L'ID NON C'È, CHIAMIAMO IL SALVATAGGIO IN BACKGROUND!
|
||||||
if (targetId == null) {
|
if (targetId == null) {
|
||||||
if (widget.onGenerateIdForQr != null) {
|
if (widget.onEnsureEntitySaved != null) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
@@ -518,7 +518,7 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Aspettiamo che il TicketFormCubit faccia il suo lavoro
|
// 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
|
// Se fallisce (es. validazione form non passata), ci fermiamo
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ class OperationFormScreen extends StatefulWidget {
|
|||||||
class _OperationFormScreenState extends State<OperationFormScreen> {
|
class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
|
// 🥷 IL NUOVO FLAG: Ci ricorderà se vogliamo davvero uscire!
|
||||||
|
bool _isClosingIntent = false;
|
||||||
|
|
||||||
final _referenceController = TextEditingController();
|
final _referenceController = TextEditingController();
|
||||||
final _noteController = TextEditingController();
|
final _noteController = TextEditingController();
|
||||||
final _freeTextSubtypeController = TextEditingController();
|
final _freeTextSubtypeController = TextEditingController();
|
||||||
@@ -101,10 +104,11 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
|||||||
required bool keepAdding,
|
required bool keepAdding,
|
||||||
}) {
|
}) {
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
|
// Se non stiamo facendo "Salva e Aggiungi Altro", il nostro intento è chiudere
|
||||||
|
_isClosingIntent = !keepAdding;
|
||||||
|
|
||||||
_flushControllersToCubit();
|
_flushControllersToCubit();
|
||||||
// Aggiorniamo prima lo stato bersaglio nel cubit
|
|
||||||
context.read<OperationFormCubit>().updateFields(status: targetStatus);
|
context.read<OperationFormCubit>().updateFields(status: targetStatus);
|
||||||
// Poi chiamiamo il salvataggio
|
|
||||||
context.read<OperationFormCubit>().saveOperation(
|
context.read<OperationFormCubit>().saveOperation(
|
||||||
targetStatus: targetStatus,
|
targetStatus: targetStatus,
|
||||||
keepAdding: keepAdding,
|
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;
|
if (!_formKey.currentState!.validate()) return null;
|
||||||
|
|
||||||
|
// 🥷 Diciamo esplicitamente al sistema che NON vogliamo uscire dalla pagina
|
||||||
|
_isClosingIntent = false;
|
||||||
|
|
||||||
_flushControllersToCubit();
|
_flushControllersToCubit();
|
||||||
|
|
||||||
// Lo leggiamo pulito pulito dal context, perché c'è!
|
|
||||||
final attachmentsBloc = context.read<AttachmentsBloc>();
|
final attachmentsBloc = context.read<AttachmentsBloc>();
|
||||||
|
|
||||||
final newId = await context.read<OperationFormCubit>().saveOperationDraft();
|
final newId = await context.read<OperationFormCubit>().saveOperationDraft();
|
||||||
@@ -151,8 +159,15 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
|||||||
if (state.status == OperationFormStatus.ready && !_isInitialized) {
|
if (state.status == OperationFormStatus.ready && !_isInitialized) {
|
||||||
_syncTextControllers(state.operation);
|
_syncTextControllers(state.operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🥷 ORA POPPA SOLO SE L'INTENTO ERA QUELLO DI USCIRE!
|
||||||
if (state.status == OperationFormStatus.success) {
|
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) {
|
} else if (state.status == OperationFormStatus.successAndAddAnother) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
@@ -626,7 +641,7 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
|||||||
parentType: AttachmentParentType.operation,
|
parentType: AttachmentParentType.operation,
|
||||||
parentId: state.operation.id,
|
parentId: state.operation.id,
|
||||||
titleForUpload: state.operation.customer?.name ?? 'Nuova Pratica',
|
titleForUpload: state.operation.customer?.name ?? 'Nuova Pratica',
|
||||||
onGenerateIdForQr: _generateIdForQr,
|
onEnsureEntitySaved: _ensureEntitySaved, // 🥷 Il nuovo nome!
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
name: flux
|
name: flux
|
||||||
description: "Gestione attività negozio di telefonia"
|
description: "Gestione attività negozio di telefonia"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
version: 1.1.21+39
|
version: 1.1.22+40
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.11.3
|
sdk: ^3.11.3
|
||||||
|
|||||||
Reference in New Issue
Block a user