fixed issues in space

This commit is contained in:
hannathkadher
2024-10-30 11:04:36 +04:00
parent d025da6daf
commit 489789da0a
4 changed files with 26 additions and 13 deletions

View File

@ -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();
}
}