new operation form almost ready
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -213,14 +213,19 @@ class OperationsCubit extends Cubit<OperationsState> {
|
||||
String? customerDisplayName,
|
||||
String? type,
|
||||
String? providerId,
|
||||
String? providerDisplayName,
|
||||
String? subtype,
|
||||
DateTime? expirationDate,
|
||||
int? quantity,
|
||||
String? modelId,
|
||||
String? modelDisplayName,
|
||||
// Aggiungiamo questi flag per forzare la pulizia dei campi quando cambi tipo
|
||||
bool clearProvider = false,
|
||||
bool clearType = false,
|
||||
bool clearSubtype = false,
|
||||
bool clearExpiration = false,
|
||||
bool clearQuantity = false,
|
||||
bool clearModel = false,
|
||||
}) {
|
||||
if (state.currentOperation == null) return;
|
||||
|
||||
@@ -231,16 +236,48 @@ class OperationsCubit extends Cubit<OperationsState> {
|
||||
final updated = current.copyWith(
|
||||
customerId: customerId,
|
||||
customerDisplayName: customerDisplayName,
|
||||
type: clearType ? null : type,
|
||||
subtype: clearSubtype ? null : subtype,
|
||||
expirationDate: clearExpiration ? null : expirationDate,
|
||||
|
||||
// Se clearProvider è true, forziamo una stringa vuota (o null se il tuo modello lo supporta)
|
||||
providerId: clearProvider ? null : (providerId ?? current.providerId),
|
||||
// Idem per subtype e date.
|
||||
// Se expirationDate è nullabile nel copyWith, dovresti poterlo gestire
|
||||
quantity: quantity ?? current.quantity,
|
||||
providerDisplayName: clearProvider
|
||||
? null
|
||||
: (providerDisplayName ?? current.providerDisplayName),
|
||||
quantity: clearQuantity ? 1 : (quantity ?? current.quantity),
|
||||
type: clearType ? null : (type ?? current.type),
|
||||
subtype: clearSubtype ? null : (subtype ?? current.subtype),
|
||||
expirationDate: clearExpiration
|
||||
? null
|
||||
: (expirationDate ?? current.expirationDate),
|
||||
modelId: clearModel ? null : (modelId ?? current.modelId),
|
||||
modelDisplayName: clearModel
|
||||
? null
|
||||
: (modelDisplayName ?? current.modelDisplayName),
|
||||
);
|
||||
|
||||
emit(state.copyWith(currentOperation: updated));
|
||||
}
|
||||
|
||||
// Metodo di utilità per calcolare la data X mesi da oggi
|
||||
DateTime _calculateMonths(int months) {
|
||||
final now = DateTime.now();
|
||||
return DateTime(now.year, now.month + months, now.day);
|
||||
}
|
||||
|
||||
// Quando l'utente seleziona un tipo, impostiamo il default
|
||||
void setTypeWithSmartDefault(String type) {
|
||||
DateTime? defaultDate;
|
||||
|
||||
if (type == 'Energy') defaultDate = _calculateMonths(24);
|
||||
if (type == 'Fin') defaultDate = _calculateMonths(30);
|
||||
if (type == 'Entertainment') defaultDate = _calculateMonths(12);
|
||||
|
||||
updateOperationFields(
|
||||
type: type,
|
||||
expirationDate: defaultDate,
|
||||
clearProvider: true,
|
||||
clearSubtype: true,
|
||||
clearModel: true,
|
||||
clearQuantity: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user