Add flush sensor icon to assets and enhancement code

This commit is contained in:
mohammad
2025-05-07 10:11:33 +03:00
parent 14a5d26ef9
commit 9cc4538dc5
10 changed files with 126 additions and 83 deletions
@@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/flush_sensor_bloc/flush_sensor_event.dart';
import 'package:syncrow_app/features/devices/bloc/flush_sensor_bloc/flush_sensor_state.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/model/device_info_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/flush_sensor_model.dart';
import 'package:syncrow_app/features/devices/model/status_model.dart';
@@ -15,17 +16,17 @@ class FlushSensorBloc extends Bloc<FlushSensorEvent, FlushSensorState> {
late DeviceModel deviceModel;
late FlushSensorModel deviceStatus;
FlushSensorBloc({required this.deviceId}) : super(InitialState()) {
on<InitialEvent>(_fetchFlushSensorStatus);
on<ChangeIndicatorEvent>(_changeIndicator);
on<ChangeValueEvent>(_changeValue);
on<WallSensorUpdatedEvent>(_flushSensorUpdated);
on<GetDeviceReportsEvent>(_getDeviceReports);
FlushSensorBloc({required this.deviceId}) : super(FlushSensorInitialState()) {
on<FlushSensorInitialEvent>(_fetchFlushSensorStatus);
on<FlushSensorChangeIndicatorEvent>(_changeIndicator);
on<FlushSensorChangeValueEvent>(_changeValue);
on<FlushSensorUpdatedEvent>(_flushSensorUpdated);
on<FlushSensorGetDeviceReportsEvent>(_getDeviceReports);
}
void _fetchFlushSensorStatus(
InitialEvent event, Emitter<FlushSensorState> emit) async {
emit(LoadingInitialState());
FlushSensorInitialEvent event, Emitter<FlushSensorState> emit) async {
emit(FlushSensorLoadingInitialState());
try {
var response = await DevicesAPI.getDeviceStatus(deviceId);
List<StatusModel> statusModelList = [];
@@ -33,10 +34,10 @@ class FlushSensorBloc extends Bloc<FlushSensorEvent, FlushSensorState> {
statusModelList.add(StatusModel.fromJson(status));
}
deviceStatus = FlushSensorModel.fromJson(statusModelList);
emit(UpdateState(flushSensorModel: deviceStatus));
emit(FlushSensorUpdateState(flushSensorModel: deviceStatus));
_listenToChanges();
} catch (e) {
emit(FailedState(error: e.toString()));
emit(FlushSensorFailedState(error: e.toString()));
return;
}
}
@@ -60,7 +61,7 @@ class FlushSensorBloc extends Bloc<FlushSensorEvent, FlushSensorState> {
});
deviceStatus = FlushSensorModel.fromJson(statusList);
if (!isClosed) {
add(WallSensorUpdatedEvent());
add(FlushSensorUpdatedEvent());
}
});
} catch (_) {
@@ -79,51 +80,53 @@ class FlushSensorBloc extends Bloc<FlushSensorEvent, FlushSensorState> {
}
_flushSensorUpdated(
WallSensorUpdatedEvent event, Emitter<FlushSensorState> emit) {
emit(UpdateState(flushSensorModel: deviceStatus));
FlushSensorUpdatedEvent event, Emitter<FlushSensorState> emit) {
emit(FlushSensorUpdateState(flushSensorModel: deviceStatus));
}
void _changeIndicator(
ChangeIndicatorEvent event, Emitter<FlushSensorState> emit) async {
emit(LoadingNewSate(flushSensorModel: deviceStatus));
void _changeIndicator(FlushSensorChangeIndicatorEvent event,
Emitter<FlushSensorState> emit) async {
emit(FlushSensorLoadingNewSate(flushSensorModel: deviceStatus));
try {
final response = await DevicesAPI.controlDevice(
DeviceControlModel(
deviceId: deviceId, code: 'indicator', value: !event.value),
deviceId);
} catch (e) {
emit(FailedState(error: e.toString()));
emit(FlushSensorFailedState(error: e.toString()));
return;
}
emit(UpdateState(flushSensorModel: deviceStatus));
emit(FlushSensorUpdateState(flushSensorModel: deviceStatus));
}
void _changeValue(
ChangeValueEvent event, Emitter<FlushSensorState> emit) async {
emit(LoadingNewSate(flushSensorModel: deviceStatus));
FlushSensorChangeValueEvent event, Emitter<FlushSensorState> emit) async {
emit(FlushSensorLoadingNewSate(flushSensorModel: deviceStatus));
try {
final response = await DevicesAPI.controlDevice(
DeviceControlModel(
deviceId: deviceId, code: event.code, value: event.value),
deviceId);
} catch (e) {
emit(FailedState(error: e.toString()));
emit(FlushSensorFailedState(error: e.toString()));
return;
}
emit(UpdateState(flushSensorModel: deviceStatus));
emit(FlushSensorUpdateState(flushSensorModel: deviceStatus));
}
void _getDeviceReports(
GetDeviceReportsEvent event, Emitter<FlushSensorState> emit) async {
emit(LoadingInitialState());
void _getDeviceReports(FlushSensorGetDeviceReportsEvent event,
Emitter<FlushSensorState> emit) async {
emit(FlushSensorLoadingInitialState());
try {
await DevicesAPI.getDeviceReports(deviceId, event.code).then((value) {
emit(DeviceReportsState(deviceReport: value, code: event.code));
emit(FlushSensorDeviceReportsState(
deviceReport: value, code: event.code));
});
} catch (e) {
emit(FailedState(error: e.toString()));
emit(FlushSensorFailedState(error: e.toString()));
return;
}
}
}
@@ -7,33 +7,35 @@ abstract class FlushSensorEvent extends Equatable {
List<Object> get props => [];
}
class LoadingEvent extends FlushSensorEvent {}
class FlushSensorLoadingEvent extends FlushSensorEvent {}
class InitialEvent extends FlushSensorEvent {}
class FlushSensorInitialEvent extends FlushSensorEvent {}
class WallSensorUpdatedEvent extends FlushSensorEvent {}
class FlushSensorInitialDeviseInfo extends FlushSensorEvent {}
class ChangeIndicatorEvent extends FlushSensorEvent {
class FlushSensorUpdatedEvent extends FlushSensorEvent {}
class FlushSensorChangeIndicatorEvent extends FlushSensorEvent {
final bool value;
const ChangeIndicatorEvent({required this.value});
const FlushSensorChangeIndicatorEvent({required this.value});
@override
List<Object> get props => [value];
}
class ChangeValueEvent extends FlushSensorEvent {
class FlushSensorChangeValueEvent extends FlushSensorEvent {
final dynamic value;
final String code;
const ChangeValueEvent({required this.value, required this.code});
const FlushSensorChangeValueEvent({required this.value, required this.code});
@override
List<Object> get props => [value, code];
}
class GetDeviceReportsEvent extends FlushSensorEvent {
class FlushSensorGetDeviceReportsEvent extends FlushSensorEvent {
final String deviceUuid;
final String code;
const GetDeviceReportsEvent({
const FlushSensorGetDeviceReportsEvent({
required this.deviceUuid,
required this.code,
});
@@ -1,4 +1,5 @@
import 'package:equatable/equatable.dart';
import 'package:syncrow_app/features/devices/model/device_info_model.dart';
import 'package:syncrow_app/features/devices/model/device_report_model.dart';
import 'package:syncrow_app/features/devices/model/flush_sensor_model.dart';
@@ -9,37 +10,43 @@ class FlushSensorState extends Equatable {
List<Object> get props => [];
}
class InitialState extends FlushSensorState {}
class FlushSensorInitialState extends FlushSensorState {}
class LoadingInitialState extends FlushSensorState {}
class FlushSensorLoadingInitialState extends FlushSensorState {}
class UpdateState extends FlushSensorState {
class FlushSensorUpdateState extends FlushSensorState {
final FlushSensorModel flushSensorModel;
const UpdateState({required this.flushSensorModel});
const FlushSensorUpdateState({required this.flushSensorModel});
@override
List<Object> get props => [flushSensorModel];
}
class LoadingNewSate extends FlushSensorState {
class FlushSensorLoadingNewSate extends FlushSensorState {
final FlushSensorModel flushSensorModel;
const LoadingNewSate({required this.flushSensorModel});
const FlushSensorLoadingNewSate({required this.flushSensorModel});
@override
List<Object> get props => [flushSensorModel];
}
class FailedState extends FlushSensorState {
class FlushSensorFailedState extends FlushSensorState {
final String error;
const FailedState({required this.error});
const FlushSensorFailedState({required this.error});
@override
List<Object> get props => [error];
}
class DeviceReportsState extends FlushSensorState {
class FlushSensorDeviceReportsState extends FlushSensorState {
final DeviceReport deviceReport;
final String code;
const DeviceReportsState({required this.deviceReport, required this.code});
const FlushSensorDeviceReportsState(
{required this.deviceReport, required this.code});
}
class FlushSensorLoadingDeviceInfo extends FlushSensorState {
final DeviceInfoModel? deviceInfo;
const FlushSensorLoadingDeviceInfo({this.deviceInfo});
}