mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-26 08:14:56 +00:00
Added selected device state/event, and clear data event to AnalyticsDevicesBloc.
This commit is contained in:
@ -13,6 +13,8 @@ class AnalyticsDevicesBloc
|
|||||||
this._analyticsDevicesService,
|
this._analyticsDevicesService,
|
||||||
) : super(const AnalyticsDevicesState()) {
|
) : super(const AnalyticsDevicesState()) {
|
||||||
on<LoadAnalyticsDevicesEvent>(_onLoadAnalyticsDevices);
|
on<LoadAnalyticsDevicesEvent>(_onLoadAnalyticsDevices);
|
||||||
|
on<SelectAnalyticsDeviceEvent>(_onSelectAnalyticsDevice);
|
||||||
|
on<ClearAnalyticsDeviceEvent>(_onClearAnalyticsDevice);
|
||||||
}
|
}
|
||||||
final AnalyticsDevicesService _analyticsDevicesService;
|
final AnalyticsDevicesService _analyticsDevicesService;
|
||||||
|
|
||||||
@ -28,6 +30,7 @@ class AnalyticsDevicesBloc
|
|||||||
AnalyticsDevicesState(
|
AnalyticsDevicesState(
|
||||||
status: AnalyticsDevicesStatus.loaded,
|
status: AnalyticsDevicesStatus.loaded,
|
||||||
devices: devices,
|
devices: devices,
|
||||||
|
selectedDevice: devices.firstOrNull,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -39,4 +42,25 @@ class AnalyticsDevicesBloc
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onSelectAnalyticsDevice(
|
||||||
|
SelectAnalyticsDeviceEvent event,
|
||||||
|
Emitter<AnalyticsDevicesState> emit,
|
||||||
|
) {
|
||||||
|
emit(
|
||||||
|
AnalyticsDevicesState(
|
||||||
|
selectedDevice: event.device,
|
||||||
|
devices: state.devices,
|
||||||
|
errorMessage: state.errorMessage,
|
||||||
|
status: state.status,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onClearAnalyticsDevice(
|
||||||
|
ClearAnalyticsDeviceEvent event,
|
||||||
|
Emitter<AnalyticsDevicesState> emit,
|
||||||
|
) {
|
||||||
|
emit(const AnalyticsDevicesState());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,3 +15,16 @@ final class LoadAnalyticsDevicesEvent extends AnalyticsDevicesEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [param];
|
List<Object> get props => [param];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class SelectAnalyticsDeviceEvent extends AnalyticsDevicesEvent {
|
||||||
|
const SelectAnalyticsDeviceEvent(this.device);
|
||||||
|
|
||||||
|
final AnalyticsDevice device;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [device];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class ClearAnalyticsDeviceEvent extends AnalyticsDevicesEvent {
|
||||||
|
const ClearAnalyticsDeviceEvent();
|
||||||
|
}
|
||||||
|
|||||||
@ -7,12 +7,14 @@ final class AnalyticsDevicesState extends Equatable {
|
|||||||
this.status = AnalyticsDevicesStatus.initial,
|
this.status = AnalyticsDevicesStatus.initial,
|
||||||
this.devices = const [],
|
this.devices = const [],
|
||||||
this.errorMessage,
|
this.errorMessage,
|
||||||
|
this.selectedDevice,
|
||||||
});
|
});
|
||||||
|
|
||||||
final AnalyticsDevicesStatus status;
|
final AnalyticsDevicesStatus status;
|
||||||
final List<AnalyticsDevice> devices;
|
final List<AnalyticsDevice> devices;
|
||||||
|
final AnalyticsDevice? selectedDevice;
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [status, devices, errorMessage];
|
List<Object?> get props => [status, devices, errorMessage, selectedDevice];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user