mah....volare
This commit is contained in:
@@ -5,35 +5,57 @@ enum OperationListStatus { initial, loading, success, failure }
|
||||
class OperationListState extends Equatable {
|
||||
final OperationListStatus status;
|
||||
final List<OperationModel> operations;
|
||||
final bool hasReachedMax;
|
||||
final String? errorMessage;
|
||||
final String query;
|
||||
|
||||
// Paginazione Ibrida
|
||||
final int currentPage;
|
||||
final int itemsPerPage;
|
||||
final int totalItems;
|
||||
final bool hasReachedMax;
|
||||
|
||||
// 🥷 I FILTRI MANCANTI (Riparati!)
|
||||
final String? searchTerm;
|
||||
final DateTimeRange? dateRange;
|
||||
|
||||
const OperationListState({
|
||||
this.status = OperationListStatus.initial,
|
||||
this.operations = const [],
|
||||
this.hasReachedMax = false,
|
||||
this.errorMessage,
|
||||
this.query = '',
|
||||
this.currentPage = 1,
|
||||
this.itemsPerPage = 25,
|
||||
this.totalItems = 0,
|
||||
this.hasReachedMax = false,
|
||||
this.searchTerm,
|
||||
this.dateRange,
|
||||
});
|
||||
|
||||
int get totalPages => (totalItems / itemsPerPage).ceil();
|
||||
|
||||
// 🥷 COPYWITH AVANZATO: Gestisce lo sbiancamento dei filtri alla perfezione
|
||||
OperationListState copyWith({
|
||||
OperationListStatus? status,
|
||||
List<OperationModel>? operations,
|
||||
bool? hasReachedMax,
|
||||
String? errorMessage,
|
||||
String? query,
|
||||
DateTimeRange? dateRange,
|
||||
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
|
||||
}) {
|
||||
return OperationListState(
|
||||
status: status ?? this.status,
|
||||
operations: operations ?? this.operations,
|
||||
errorMessage: errorMessage ?? this.errorMessage,
|
||||
currentPage: currentPage ?? this.currentPage,
|
||||
itemsPerPage: itemsPerPage ?? this.itemsPerPage,
|
||||
totalItems: totalItems ?? this.totalItems,
|
||||
hasReachedMax: hasReachedMax ?? this.hasReachedMax,
|
||||
errorMessage: errorMessage,
|
||||
query: query ?? this.query,
|
||||
dateRange: dateRange ?? this.dateRange,
|
||||
|
||||
// Se passi la funzione la eseguiamo, altrimenti teniamo il valore corrente
|
||||
searchTerm: searchTerm != null ? searchTerm() : this.searchTerm,
|
||||
dateRange: dateRange != null ? dateRange() : this.dateRange,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -41,9 +63,12 @@ class OperationListState extends Equatable {
|
||||
List<Object?> get props => [
|
||||
status,
|
||||
operations,
|
||||
hasReachedMax,
|
||||
errorMessage,
|
||||
query,
|
||||
currentPage,
|
||||
itemsPerPage,
|
||||
totalItems,
|
||||
hasReachedMax,
|
||||
searchTerm,
|
||||
dateRange,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user