mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-12-02 11:04:58 +00:00
Add functionality to fetch devices by room ID
Added a new method in DevicesCubit to fetch devices by room ID and updated related classes and API calls to support this functionality.
This commit is contained in:
@ -16,6 +16,7 @@ import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_view.dart';
|
||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||
import 'package:syncrow_app/services/api/network_exception.dart';
|
||||
import 'package:syncrow_app/services/api/spaces_api.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
part 'devices_state.dart';
|
||||
@ -24,6 +25,9 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
DevicesCubit() : super(DevicesInitial()) {
|
||||
if (HomeCubit.getInstance().selectedSpace != null) {
|
||||
fetchGroups(HomeCubit.getInstance().selectedSpace!.id!);
|
||||
for (var room in HomeCubit.getInstance().selectedSpace!.rooms!) {
|
||||
fetchDevicesByRoomId(room.id!);
|
||||
}
|
||||
}
|
||||
}
|
||||
bool _isClosed = false;
|
||||
@ -251,6 +255,26 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
}
|
||||
}
|
||||
|
||||
fetchDevicesByRoomId(int roomId) async {
|
||||
if (_isClosed) return;
|
||||
|
||||
try {
|
||||
emit(GetDevicesLoading());
|
||||
int roomIndex = HomeCubit.getInstance()
|
||||
.selectedSpace!
|
||||
.rooms!
|
||||
.indexWhere((element) => element.id == roomId);
|
||||
HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices =
|
||||
await SpacesAPI.getDevicesByRoomId(roomId);
|
||||
|
||||
emit(GetDevicesSuccess());
|
||||
} on DioException catch (error) {
|
||||
emit(
|
||||
GetDevicesError(ServerFailure.fromDioError(error).errMessage),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///Lights
|
||||
onHorizontalDragUpdate(DeviceModel light, double dx, double screenWidth) {
|
||||
double newBrightness = (dx / (screenWidth - 15) * 100);
|
||||
|
||||
Reference in New Issue
Block a user