mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
fixed issues in space
This commit is contained in:
@ -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