Refactor service management: streamline service form, enhance state management, and improve loading logic
This commit is contained in:
57
lib/features/services/blocs/services_state.dart
Normal file
57
lib/features/services/blocs/services_state.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
part of 'services_cubit.dart';
|
||||
|
||||
class ServicesState extends Equatable {
|
||||
final List<ServiceModel> allServices;
|
||||
final ServiceModel? currentService; // La bozza che stiamo editando
|
||||
final bool isLoading;
|
||||
final bool isSaving; // Per mostrare il caricamento solo sul tasto salva
|
||||
final String? errorMessage;
|
||||
final String query;
|
||||
final DateTimeRange? dateRange;
|
||||
final bool hasReachedMax;
|
||||
|
||||
const ServicesState({
|
||||
this.allServices = const [],
|
||||
this.currentService,
|
||||
this.isLoading = false,
|
||||
this.isSaving = false,
|
||||
this.errorMessage,
|
||||
this.query = '',
|
||||
this.dateRange,
|
||||
this.hasReachedMax = false,
|
||||
});
|
||||
|
||||
ServicesState copyWith({
|
||||
List<ServiceModel>? allServices,
|
||||
ServiceModel? currentService,
|
||||
bool? isLoading,
|
||||
bool? isSaving,
|
||||
String? errorMessage,
|
||||
String? query,
|
||||
DateTimeRange? dateRange,
|
||||
bool? hasReachedMax,
|
||||
}) {
|
||||
return ServicesState(
|
||||
allServices: allServices ?? this.allServices,
|
||||
currentService: currentService ?? this.currentService,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
isSaving: isSaving ?? this.isSaving,
|
||||
errorMessage: errorMessage,
|
||||
query: query ?? this.query,
|
||||
dateRange: dateRange ?? this.dateRange,
|
||||
hasReachedMax: hasReachedMax ?? this.hasReachedMax,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
allServices,
|
||||
currentService,
|
||||
isLoading,
|
||||
isSaving,
|
||||
errorMessage,
|
||||
query,
|
||||
dateRange,
|
||||
hasReachedMax,
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user