From 3f2f55d6c2a0041111534dc557b5d7ba01870b21 Mon Sep 17 00:00:00 2001 From: Mark M2 Macbook Date: Tue, 19 May 2026 12:03:03 +0200 Subject: [PATCH] auto isBusiness based on customer selected --- .../operations/blocs/operation_form_cubit.dart | 13 ++++++++++--- .../operations/ui/operation_form_screen.dart | 5 ++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/features/operations/blocs/operation_form_cubit.dart b/lib/features/operations/blocs/operation_form_cubit.dart index 726d4e4..e10f742 100644 --- a/lib/features/operations/blocs/operation_form_cubit.dart +++ b/lib/features/operations/blocs/operation_form_cubit.dart @@ -191,7 +191,6 @@ class OperationFormCubit extends Cubit { // --- GESTIONE DEI CAMPI IN TEMPO REALE --- void updateFields({ - CustomerModel? customer, String? reference, String? note, String? type, @@ -224,8 +223,6 @@ class OperationFormCubit extends Cubit { if (quantity != null && quantity > 0) newQuantity = quantity; final updated = current.copyWith( - customer: customer ?? current.customer, - customerId: customer?.id ?? current.customerId, reference: reference ?? current.reference, note: note ?? current.note, providerId: clearProvider ? null : (providerId ?? current.providerId), @@ -254,6 +251,16 @@ class OperationFormCubit extends Cubit { emit(state.copyWith(operation: updated)); } + void updateCustomer(CustomerModel customer) { + final bool isBusiness = customer.isBusiness; + final updatedOperation = state.operation.copyWith( + customer: customer, + customerId: customer.id, + isBusiness: isBusiness, + ); + emit(state.copyWith(operation: updatedOperation)); + } + // --- UTILS --- void setTypeWithSmartDefault(String type) { diff --git a/lib/features/operations/ui/operation_form_screen.dart b/lib/features/operations/ui/operation_form_screen.dart index 55b97c0..22de7c7 100644 --- a/lib/features/operations/ui/operation_form_screen.dart +++ b/lib/features/operations/ui/operation_form_screen.dart @@ -387,9 +387,8 @@ class _OperationFormScreenState extends State { children: [ SharedCustomerSection( customer: state.operation.customer, - onCustomerSelected: (customer) => context - .read() - .updateFields(customer: customer), + onCustomerSelected: (customer) => + context.read().updateCustomer(customer), ), const SizedBox(height: 16), TextFormField(