Fixed toJson methods

This commit is contained in:
2025-11-18 23:46:32 +01:00
parent 2da2e28cb6
commit fd86f5193f
3 changed files with 13 additions and 9 deletions

View File

@@ -35,7 +35,11 @@ class Game {
winner = json['winner'] ?? '';
/// Converts the Game instance to a JSON object.
String toJson() {
return 'Game{id: $id,name: $name,players: $players,group: $group,winner: $winner}';
}
Map<String, dynamic> toJson() => {
'id': id,
'name': name,
'players': players?.map((player) => player.toJson()).toList(),
'group': group?.toJson(),
'winner': winner,
};
}

View File

@@ -23,7 +23,9 @@ class Group {
.toList();
/// Converts the Group instance to a JSON object.
String toJson() {
return 'Group{id: $id, name: $name,members: $members}';
}
Map<String, dynamic> toJson() => {
'id': id,
'name': name,
'members': members.map((member) => member.toJson()).toList(),
};
}

View File

@@ -17,7 +17,5 @@ class Player {
name = json['name'];
/// Converts the Player instance to a JSON object.
String toJson() {
return 'Player{id: $id,name: $name}';
}
Map<String, dynamic> toJson() => {'id': id, 'name': name};
}