From 8a1b582f4e0599e8d88bd1c0266f86463f976e9b Mon Sep 17 00:00:00 2001 From: mark-cachy Date: Tue, 19 May 2026 16:00:40 +0200 Subject: [PATCH] fixes --- .../shared_forms/customer_section.dart | 10 ++- .../shared_forms/shared_files_section.dart | 18 +++--- .../customers/ui/quick_customer_dialog.dart | 63 ++++++++++--------- .../operations/ui/operation_form_screen.dart | 12 ++-- .../ui/widgets/details_section.dart | 6 +- 5 files changed, 62 insertions(+), 47 deletions(-) diff --git a/lib/core/widgets/shared_forms/customer_section.dart b/lib/core/widgets/shared_forms/customer_section.dart index 0cc8956..8be7615 100644 --- a/lib/core/widgets/shared_forms/customer_section.dart +++ b/lib/core/widgets/shared_forms/customer_section.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flux/core/routes/routes.dart'; +import 'package:flux/features/customers/blocs/customer_form_cubit.dart'; import 'package:flux/features/customers/blocs/customers_list_cubit.dart'; import 'package:flux/features/customers/models/customer_model.dart'; import 'package:flux/features/customers/ui/quick_customer_dialog.dart'; @@ -279,9 +280,12 @@ class SharedCustomerSection extends StatelessWidget { builder: (dialogContext) { return BlocProvider.value( value: context.read(), - child: QuickCustomerDialog( - initialQuery: - currentSearchQuery, // <-- Passiamo quello che ha digitato! + child: BlocProvider( + create: (context) => CustomerFormCubit(), + child: QuickCustomerDialog( + initialQuery: + currentSearchQuery, // <-- Passiamo quello che ha digitato! + ), ), ); }, diff --git a/lib/core/widgets/shared_forms/shared_files_section.dart b/lib/core/widgets/shared_forms/shared_files_section.dart index 79802c9..7d60642 100644 --- a/lib/core/widgets/shared_forms/shared_files_section.dart +++ b/lib/core/widgets/shared_forms/shared_files_section.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flux/core/blocs/session/session_cubit.dart'; +import 'package:flux/core/widgets/image_upload/blocs/image_upload_cubit.dart'; import 'package:flux/core/widgets/image_upload/ui/image_upload_screen.dart'; import 'package:flux/core/widgets/qr_upload_dialog.dart'; import 'package:flux/features/attachments/blocs/attachments_bloc.dart'; @@ -98,13 +99,16 @@ class SharedFilesSection extends StatelessWidget { MaterialPageRoute( builder: (_) => BlocProvider.value( value: bloc, - child: ImageUploadScreen( - title: titleNameForUpload, - companyId: GetIt.I - .get() - .state - .company! - .id!, + child: BlocProvider( + create: (context) => ImageUploadCubit(), + child: ImageUploadScreen( + title: titleNameForUpload, + companyId: GetIt.I + .get() + .state + .company! + .id!, + ), ), ), ), diff --git a/lib/features/customers/ui/quick_customer_dialog.dart b/lib/features/customers/ui/quick_customer_dialog.dart index 45dfcb6..a08e776 100644 --- a/lib/features/customers/ui/quick_customer_dialog.dart +++ b/lib/features/customers/ui/quick_customer_dialog.dart @@ -67,36 +67,39 @@ class _QuickCustomerDialogState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - Row( - children: [ - ChoiceChip( - label: const Text('Privato (Domestico)'), - selected: _isBusiness == false, - selectedColor: Colors.blue.withValues(alpha: 0.2), - checkmarkColor: Colors.blue.shade700, - onSelected: (selected) { - if (selected) { - setState(() { - _isBusiness = false; - }); - } - }, - ), - const SizedBox(width: 12), - ChoiceChip( - label: const Text('Business (P.IVA)'), - selected: _isBusiness == true, - selectedColor: Colors.orange.withValues(alpha: 0.2), - checkmarkColor: Colors.orange.shade700, - onSelected: (selected) { - if (selected) { - setState(() { - _isBusiness = true; - }); - } - }, - ), - ], + SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: [ + ChoiceChip( + label: const Text('Privato (Domestico)'), + selected: _isBusiness == false, + selectedColor: Colors.blue.withValues(alpha: 0.2), + checkmarkColor: Colors.blue.shade700, + onSelected: (selected) { + if (selected) { + setState(() { + _isBusiness = false; + }); + } + }, + ), + const SizedBox(width: 12), + ChoiceChip( + label: const Text('Business (P.IVA)'), + selected: _isBusiness == true, + selectedColor: Colors.orange.withValues(alpha: 0.2), + checkmarkColor: Colors.orange.shade700, + onSelected: (selected) { + if (selected) { + setState(() { + _isBusiness = true; + }); + } + }, + ), + ], + ), ), const Divider(height: 32), TextField( diff --git a/lib/features/operations/ui/operation_form_screen.dart b/lib/features/operations/ui/operation_form_screen.dart index 22de7c7..3fe122e 100644 --- a/lib/features/operations/ui/operation_form_screen.dart +++ b/lib/features/operations/ui/operation_form_screen.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flux/core/widgets/shared_forms/attachments_section.dart'; import 'package:flux/features/attachments/blocs/attachments_bloc.dart'; import 'package:flux/features/operations/blocs/operation_form_cubit.dart'; import 'package:flux/features/operations/models/operation_model.dart'; @@ -39,7 +40,7 @@ class _OperationFormScreenState extends State { 'Energy', 'Fin', 'Entertainment', - 'Custom', + 'Altro', ]; bool _isInitialized = false; @@ -113,9 +114,10 @@ class _OperationFormScreenState extends State { Future _generateIdForQr() async { if (!_formKey.currentState!.validate()) return null; _flushControllersToCubit(); + + // Lo leggiamo pulito pulito dal context, perché c'è! final attachmentsBloc = context.read(); - // Assicurati che questo metodo esista nel Cubit (come per il Ticket) final newId = await context.read().saveOperationDraft(); if (newId != null && context.mounted) { attachmentsBloc.add(ParentEntitySavedEvent(newId)); @@ -602,8 +604,10 @@ class _OperationFormScreenState extends State { icon: Icons.attach_file, themeColor: Colors.deepPurple, children: [ - SharedFilesSection( - titleNameForUpload: state.operation.customer?.name ?? 'Nuova Pratica', + SharedAttachmentsSection( + parentType: AttachmentParentType.operation, + parentId: state.operation.id, + titleForUpload: state.operation.customer?.name ?? 'Nuova Pratica', onGenerateIdForQr: _generateIdForQr, ), ], diff --git a/lib/features/operations/ui/widgets/details_section.dart b/lib/features/operations/ui/widgets/details_section.dart index 586d6bb..566ae5f 100644 --- a/lib/features/operations/ui/widgets/details_section.dart +++ b/lib/features/operations/ui/widgets/details_section.dart @@ -27,7 +27,7 @@ class OperationDetailsSection extends StatelessWidget { ProviderModel provider, String operationType, ) { - if (operationType == 'Custom') return true; + if (operationType == 'Altro') return true; // Controlliamo che il fornitore abbia il ruolo specifico nel suo array switch (operationType) { @@ -241,7 +241,7 @@ class OperationDetailsSection extends StatelessWidget { ], // 3. SCENARIO ENTERTAINMENT O CUSTOM (Testo libero) - if (currentType == 'Entertainment' || currentType == 'Custom') ...[ + if (currentType == 'Entertainment' || currentType == 'Altro') ...[ TextFormField( controller: freeTextSubtypeController, decoration: InputDecoration( @@ -258,7 +258,7 @@ class OperationDetailsSection extends StatelessWidget { 'Energy', 'Fin', 'Entertainment', - 'Custom', + 'Altro', ].contains(currentType)) ...[ const SizedBox(height: 8), durationQuickPicks, // Passiamo i chips dall'esterno