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:
Mohammad Salameh
2024-04-02 12:12:54 +03:00
parent 1397778123
commit 5dc4f96a71
8 changed files with 75 additions and 26 deletions

View File

@ -20,17 +20,13 @@ class HomeCubit extends Cubit<HomeState> {
// Create a private static instance variable
static HomeCubit? _instance;
HomeCubit._() : super(HomeInitial()) {
if (spaces != null) {
if (selectedSpace == null) {
fetchSpaces().then((value) {
if (selectedSpace != null) {
print('selectedSpace: ${selectedSpace!.name}');
fetchRooms(selectedSpace!);
}
});
}
} else {
fetchSpaces(); // this is for the first time
if (selectedSpace == null) {
fetchSpaces().then((value) {
if (selectedSpace != null) {
print('selectedSpace: ${selectedSpace!.name}');
fetchRooms(selectedSpace!);
}
});
}
}
static HomeCubit getInstance() {
@ -128,7 +124,7 @@ class HomeCubit extends Cubit<HomeState> {
fetchRooms(SpaceModel space) async {
emit(GetSpaceRoomsLoading());
try {
space.rooms = await SpacesAPI.getRooms(space.id!);
space.rooms = await SpacesAPI.getRoomsBySpaceId(space.id!);
if (space.rooms != null) {
emit(GetSpaceRoomsLoaded(space.rooms!));
} else {