hi
This commit is contained in:
@@ -247,35 +247,30 @@ class AttachmentsSection extends StatelessWidget {
|
|||||||
Future<void> _handleGenerateQr(BuildContext context) async {
|
Future<void> _handleGenerateQr(BuildContext context) async {
|
||||||
final cubit = context.read<ServicesCubit>();
|
final cubit = context.read<ServicesCubit>();
|
||||||
var currentService = cubit.state.currentService;
|
var currentService = cubit.state.currentService;
|
||||||
final navigator = Navigator.of(context);
|
|
||||||
|
|
||||||
// 1. SE LA PRATICA E' NUOVA (Manca l'ID)
|
// 1. CATTURIAMO IL BLOC MENTRE SIAMO ANCORA NELLA PAGINA
|
||||||
|
final serviceFilesBloc = context.read<ServiceFilesBloc>();
|
||||||
|
|
||||||
|
// 2. SE LA PRATICA E' NUOVA (Manca l'ID)
|
||||||
if (currentService == null || currentService.id == null) {
|
if (currentService == null || currentService.id == null) {
|
||||||
// Chiediamo conferma
|
// NIENTE BlocListener qui! Solo un semplice Dialog di conferma
|
||||||
final bool? confirm = await showDialog<bool>(
|
final bool? confirm = await showDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (ctx) => BlocListener<ServiceFilesBloc, ServiceFilesState>(
|
builder: (ctx) => AlertDialog(
|
||||||
listener: (context, state) {
|
title: const Text("Salvataggio Necessario"),
|
||||||
if (state.status == ServiceFilesStatus.success) {
|
content: const Text(
|
||||||
navigator.pop();
|
"Per generare il QR Code e caricare file dal telefono, la pratica deve essere prima salvata in BOZZA.\n\nVuoi salvare ora?",
|
||||||
}
|
|
||||||
},
|
|
||||||
child: AlertDialog(
|
|
||||||
title: const Text("Salvataggio Necessario"),
|
|
||||||
content: const Text(
|
|
||||||
"Per generare il QR Code e caricare file dal telefono, la pratica deve essere prima salvata in BOZZA.\n\nVuoi salvare ora?",
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(ctx, false),
|
|
||||||
child: const Text("Annulla"),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () => Navigator.pop(ctx, true),
|
|
||||||
child: const Text("Salva in Bozza"),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(ctx, false),
|
||||||
|
child: const Text("Annulla"),
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () => Navigator.pop(ctx, true),
|
||||||
|
child: const Text("Salva in Bozza"),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -287,24 +282,36 @@ class AttachmentsSection extends StatelessWidget {
|
|||||||
// Recuperiamo il servizio aggiornato con l'ID!
|
// Recuperiamo il servizio aggiornato con l'ID!
|
||||||
currentService = cubit.state.currentService;
|
currentService = cubit.state.currentService;
|
||||||
|
|
||||||
if (currentService?.id == null) {
|
if (currentService?.id == null) return;
|
||||||
// Se c'è stato un errore nel salvataggio, usciamo
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. ORA ABBIAMO L'ID SICURO -> MOSTRIAMO IL QR!
|
// 3. MOSTRIAMO IL QR CODE (Con il Ponte e l'Auto-Chiusura!)
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
// Creiamo un nome leggibile da passare nel link
|
|
||||||
final nomePratica = "Pratica ${currentService?.customerDisplayName ?? ''}"
|
final nomePratica = "Pratica ${currentService?.customerDisplayName ?? ''}"
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => QrUploadDialog(
|
builder: (dialogContext) => BlocProvider.value(
|
||||||
deepLinkUrl:
|
// INIETTIAMO IL BLOC NEL CONTESTO DEL DIALOG ALIENO
|
||||||
'fluxapp://service/${currentService!.id}/upload?name=${Uri.encodeComponent(nomePratica)}',
|
value: serviceFilesBloc,
|
||||||
title: 'Scatta per\n$nomePratica',
|
|
||||||
|
// ORA METTIAMO L'AUTO-CHIUSURA SUL QR CODE!
|
||||||
|
child: BlocListener<ServiceFilesBloc, ServiceFilesState>(
|
||||||
|
listener: (context, state) {
|
||||||
|
// Se arrivano file remoti e lo stato è success, chiudiamo il QR!
|
||||||
|
// (Nota: usiamo dialogContext per assicurarci di chiudere il popup giusto)
|
||||||
|
if (state.status == ServiceFilesStatus.success &&
|
||||||
|
state.remoteFiles.isNotEmpty) {
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: QrUploadDialog(
|
||||||
|
deepLinkUrl:
|
||||||
|
'fluxapp://service/${currentService!.id}/upload?name=${Uri.encodeComponent(nomePratica)}',
|
||||||
|
title: 'Scatta per\n$nomePratica',
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user