auto isBusiness based on customer selected
This commit is contained in:
@@ -191,7 +191,6 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
// --- GESTIONE DEI CAMPI IN TEMPO REALE ---
|
// --- GESTIONE DEI CAMPI IN TEMPO REALE ---
|
||||||
|
|
||||||
void updateFields({
|
void updateFields({
|
||||||
CustomerModel? customer,
|
|
||||||
String? reference,
|
String? reference,
|
||||||
String? note,
|
String? note,
|
||||||
String? type,
|
String? type,
|
||||||
@@ -224,8 +223,6 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
if (quantity != null && quantity > 0) newQuantity = quantity;
|
if (quantity != null && quantity > 0) newQuantity = quantity;
|
||||||
|
|
||||||
final updated = current.copyWith(
|
final updated = current.copyWith(
|
||||||
customer: customer ?? current.customer,
|
|
||||||
customerId: customer?.id ?? current.customerId,
|
|
||||||
reference: reference ?? current.reference,
|
reference: reference ?? current.reference,
|
||||||
note: note ?? current.note,
|
note: note ?? current.note,
|
||||||
providerId: clearProvider ? null : (providerId ?? current.providerId),
|
providerId: clearProvider ? null : (providerId ?? current.providerId),
|
||||||
@@ -254,6 +251,16 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
emit(state.copyWith(operation: updated));
|
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 ---
|
// --- UTILS ---
|
||||||
|
|
||||||
void setTypeWithSmartDefault(String type) {
|
void setTypeWithSmartDefault(String type) {
|
||||||
|
|||||||
@@ -387,9 +387,8 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
|||||||
children: [
|
children: [
|
||||||
SharedCustomerSection(
|
SharedCustomerSection(
|
||||||
customer: state.operation.customer,
|
customer: state.operation.customer,
|
||||||
onCustomerSelected: (customer) => context
|
onCustomerSelected: (customer) =>
|
||||||
.read<OperationFormCubit>()
|
context.read<OperationFormCubit>().updateCustomer(customer),
|
||||||
.updateFields(customer: customer),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
|||||||
Reference in New Issue
Block a user