2026-05-08 12:28:14 +02:00
|
|
|
part of 'operation_list_cubit.dart';
|
|
|
|
|
|
|
|
|
|
enum OperationListStatus { initial, loading, success, failure }
|
|
|
|
|
|
|
|
|
|
class OperationListState extends Equatable {
|
|
|
|
|
final OperationListStatus status;
|
|
|
|
|
final List<OperationModel> operations;
|
|
|
|
|
final String? errorMessage;
|
2026-06-03 19:16:15 +02:00
|
|
|
|
|
|
|
|
// Paginazione Ibrida
|
|
|
|
|
final int currentPage;
|
|
|
|
|
final int itemsPerPage;
|
|
|
|
|
final int totalItems;
|
|
|
|
|
final bool hasReachedMax;
|
|
|
|
|
|
|
|
|
|
// 🥷 I FILTRI MANCANTI (Riparati!)
|
|
|
|
|
final String? searchTerm;
|
2026-05-08 12:28:14 +02:00
|
|
|
final DateTimeRange? dateRange;
|
|
|
|
|
|
|
|
|
|
const OperationListState({
|
|
|
|
|
this.status = OperationListStatus.initial,
|
|
|
|
|
this.operations = const [],
|
|
|
|
|
this.errorMessage,
|
2026-06-03 19:16:15 +02:00
|
|
|
this.currentPage = 1,
|
|
|
|
|
this.itemsPerPage = 25,
|
|
|
|
|
this.totalItems = 0,
|
|
|
|
|
this.hasReachedMax = false,
|
|
|
|
|
this.searchTerm,
|
2026-05-08 12:28:14 +02:00
|
|
|
this.dateRange,
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
int get totalPages => (totalItems / itemsPerPage).ceil();
|
|
|
|
|
|
|
|
|
|
// 🥷 COPYWITH AVANZATO: Gestisce lo sbiancamento dei filtri alla perfezione
|
2026-05-08 12:28:14 +02:00
|
|
|
OperationListState copyWith({
|
|
|
|
|
OperationListStatus? status,
|
|
|
|
|
List<OperationModel>? operations,
|
|
|
|
|
String? errorMessage,
|
2026-06-03 19:16:15 +02:00
|
|
|
int? currentPage,
|
|
|
|
|
int? itemsPerPage,
|
|
|
|
|
int? totalItems,
|
|
|
|
|
bool? hasReachedMax,
|
|
|
|
|
String? Function()? searchTerm, // Callback per gestire il null esplicito
|
|
|
|
|
DateTimeRange? Function()?
|
|
|
|
|
dateRange, // Callback per gestire il null esplicito
|
2026-05-08 12:28:14 +02:00
|
|
|
}) {
|
|
|
|
|
return OperationListState(
|
|
|
|
|
status: status ?? this.status,
|
|
|
|
|
operations: operations ?? this.operations,
|
2026-06-03 19:16:15 +02:00
|
|
|
errorMessage: errorMessage ?? this.errorMessage,
|
|
|
|
|
currentPage: currentPage ?? this.currentPage,
|
|
|
|
|
itemsPerPage: itemsPerPage ?? this.itemsPerPage,
|
|
|
|
|
totalItems: totalItems ?? this.totalItems,
|
2026-05-08 12:28:14 +02:00
|
|
|
hasReachedMax: hasReachedMax ?? this.hasReachedMax,
|
2026-06-03 19:16:15 +02:00
|
|
|
|
|
|
|
|
// Se passi la funzione la eseguiamo, altrimenti teniamo il valore corrente
|
|
|
|
|
searchTerm: searchTerm != null ? searchTerm() : this.searchTerm,
|
|
|
|
|
dateRange: dateRange != null ? dateRange() : this.dateRange,
|
2026-05-08 12:28:14 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
List<Object?> get props => [
|
|
|
|
|
status,
|
|
|
|
|
operations,
|
|
|
|
|
errorMessage,
|
2026-06-03 19:16:15 +02:00
|
|
|
currentPage,
|
|
|
|
|
itemsPerPage,
|
|
|
|
|
totalItems,
|
|
|
|
|
hasReachedMax,
|
|
|
|
|
searchTerm,
|
2026-05-08 12:28:14 +02:00
|
|
|
dateRange,
|
|
|
|
|
];
|
|
|
|
|
}
|