mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Created EnergyConsumptionByPhasesBloc
.
This commit is contained in:
@ -0,0 +1,42 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/models/phases_energy_consumption.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/params/get_energy_consumption_by_phases_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/services/energy_consumption_by_phases/energy_consumption_by_phases_service.dart';
|
||||||
|
|
||||||
|
part 'energy_consumption_by_phases_event.dart';
|
||||||
|
part 'energy_consumption_by_phases_state.dart';
|
||||||
|
|
||||||
|
class EnergyConsumptionByPhasesBloc
|
||||||
|
extends Bloc<EnergyConsumptionByPhasesEvent, EnergyConsumptionByPhasesState> {
|
||||||
|
EnergyConsumptionByPhasesBloc(
|
||||||
|
this._energyConsumptionByPhasesService,
|
||||||
|
) : super(const EnergyConsumptionByPhasesState()) {
|
||||||
|
on<LoadEnergyConsumptionByPhasesEvent>(_onLoadEnergyConsumptionByPhasesEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
final EnergyConsumptionByPhasesService _energyConsumptionByPhasesService;
|
||||||
|
|
||||||
|
Future<void> _onLoadEnergyConsumptionByPhasesEvent(
|
||||||
|
LoadEnergyConsumptionByPhasesEvent event,
|
||||||
|
Emitter<EnergyConsumptionByPhasesState> emit,
|
||||||
|
) async {
|
||||||
|
emit(state.copyWith(status: EnergyConsumptionByPhasesStatus.loading));
|
||||||
|
try {
|
||||||
|
final chartData = await _energyConsumptionByPhasesService.load(event.param);
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
status: EnergyConsumptionByPhasesStatus.loaded,
|
||||||
|
chartData: chartData,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
status: EnergyConsumptionByPhasesStatus.failure,
|
||||||
|
errorMessage: e.toString(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
part of 'energy_consumption_by_phases_bloc.dart';
|
||||||
|
|
||||||
|
sealed class EnergyConsumptionByPhasesEvent extends Equatable {
|
||||||
|
const EnergyConsumptionByPhasesEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadEnergyConsumptionByPhasesEvent extends EnergyConsumptionByPhasesEvent {
|
||||||
|
const LoadEnergyConsumptionByPhasesEvent({
|
||||||
|
required this.param,
|
||||||
|
});
|
||||||
|
|
||||||
|
final GetEnergyConsumptionByPhasesParam param;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [param];
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
part of 'energy_consumption_by_phases_bloc.dart';
|
||||||
|
|
||||||
|
enum EnergyConsumptionByPhasesStatus {
|
||||||
|
initial,
|
||||||
|
loading,
|
||||||
|
loaded,
|
||||||
|
failure,
|
||||||
|
}
|
||||||
|
|
||||||
|
final class EnergyConsumptionByPhasesState extends Equatable {
|
||||||
|
const EnergyConsumptionByPhasesState({
|
||||||
|
this.status = EnergyConsumptionByPhasesStatus.initial,
|
||||||
|
this.chartData = const <PhasesEnergyConsumption>[],
|
||||||
|
this.errorMessage,
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<PhasesEnergyConsumption> chartData;
|
||||||
|
final EnergyConsumptionByPhasesStatus status;
|
||||||
|
final String? errorMessage;
|
||||||
|
|
||||||
|
EnergyConsumptionByPhasesState copyWith({
|
||||||
|
List<PhasesEnergyConsumption>? chartData,
|
||||||
|
EnergyConsumptionByPhasesStatus? status,
|
||||||
|
String? errorMessage,
|
||||||
|
}) {
|
||||||
|
return EnergyConsumptionByPhasesState(
|
||||||
|
chartData: chartData ?? this.chartData,
|
||||||
|
status: status ?? this.status,
|
||||||
|
errorMessage: errorMessage ?? this.errorMessage,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [chartData, status, errorMessage];
|
||||||
|
}
|
Reference in New Issue
Block a user