mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-24 19:57:55 +00:00
fixed issues in space
This commit is contained in:
@@ -269,17 +269,21 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
await fetchRoomsByUnitId(selectedSpace!);
|
||||
emitSafe(GetSpacesSuccess(spaces!));
|
||||
} else {
|
||||
print("here in else");
|
||||
emitSafe(GetSpacesError("No spaces found"));
|
||||
}
|
||||
}
|
||||
|
||||
fetchRoomsByUnitId(SpaceModel space) async {
|
||||
print("Community ID: ${space.community.uuid}");
|
||||
print("Space ID: ${space.id}");
|
||||
|
||||
emitSafe(GetSpaceRoomsLoading());
|
||||
try {
|
||||
space.subspaces =
|
||||
await SpacesAPI.getSubSpaceBySpaceId(space.community.uuid, space.id);
|
||||
} catch (failure) {
|
||||
print("Error fetching subspaces: $failure");
|
||||
|
||||
emitSafe(GetSpaceRoomsError(failure.toString()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ class Community {
|
||||
Community({
|
||||
required this.uuid,
|
||||
required this.name,
|
||||
required this.description,
|
||||
this.description = '',
|
||||
});
|
||||
|
||||
factory Community.fromJson(Map<String, dynamic> json) {
|
||||
return Community(
|
||||
uuid: json['uuid'],
|
||||
name: json['name'],
|
||||
description: json['description'],
|
||||
uuid: json['uuid'] ?? '',
|
||||
name: json['name'] ?? 'Unnamed Community',
|
||||
description: json['description'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,17 @@ class SpaceModel {
|
||||
|
||||
/// Factory constructor to create an instance from JSON.
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
final spaceData = json['space'] as Map<String, dynamic>? ?? {};
|
||||
// Extract and log each part of space data
|
||||
final id = json['uuid'] ?? '';
|
||||
final name = json['spaceName'] ?? 'Unnamed Space';
|
||||
final communityJson = json['community'] ?? {};
|
||||
|
||||
return SpaceModel(
|
||||
id: json['uuid'] ?? '',
|
||||
name: spaceData['spaceName'] ?? 'Unnamed Space',
|
||||
community: Community.fromJson(spaceData['community'] ?? {}),
|
||||
subspaces: (spaceData['subspaces'] as List<dynamic>?)
|
||||
id: id,
|
||||
name: name,
|
||||
community: Community.fromJson(
|
||||
communityJson), // Ensure Community is created correctly
|
||||
subspaces: (json['subspaces'] as List<dynamic>?)
|
||||
?.map((item) => SubSpaceModel.fromJson(item))
|
||||
.toList() ??
|
||||
[],
|
||||
@@ -41,6 +45,9 @@ class SpaceModel {
|
||||
|
||||
/// Helper method to parse a list of SpaceModel from JSON.
|
||||
static List<SpaceModel> fromJsonList(List<dynamic> jsonList) {
|
||||
return jsonList.map((item) => SpaceModel.fromJson(item)).toList();
|
||||
return jsonList.map((item) {
|
||||
final spaceData = item['space']; // Extract the `space` object
|
||||
return SpaceModel.fromJson(spaceData); // Pass to SpaceModel.fromJson
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user