update match class

This commit is contained in:
gelbeinhalb
2026-01-16 10:50:03 +01:00
parent 6a9e5dc9eb
commit 072021bd4c

View File

@@ -1,4 +1,5 @@
import 'package:clock/clock.dart';
import 'package:game_tracker/data/dto/game.dart';
import 'package:game_tracker/data/dto/group.dart';
import 'package:game_tracker/data/dto/player.dart';
import 'package:uuid/uuid.dart';
@@ -7,45 +8,49 @@ class Match {
final String id;
final DateTime createdAt;
final String name;
final List<Player>? players;
final Game? game;
final Group? group;
Player? winner;
final List<Player>? players;
final String? notes;
Match({
String? id,
DateTime? createdAt,
required this.name,
this.players,
this.game,
this.group,
this.winner,
this.players,
this.notes,
}) : id = id ?? const Uuid().v4(),
createdAt = createdAt ?? clock.now();
@override
String toString() {
return 'Match{\n\tid: $id,\n\tname: $name,\n\tplayers: $players,\n\tgroup: $group,\n\twinner: $winner\n}';
return 'Match{id: $id, name: $name, game: $game, group: $group, players: $players, notes: $notes}';
}
/// Creates a Match instance from a JSON object.
Match.fromJson(Map<String, dynamic> json)
: id = json['id'],
name = json['name'],
createdAt = DateTime.parse(json['createdAt']),
name = json['name'],
game = json['game'] != null ? Game.fromJson(json['game']) : null,
group = json['group'] != null ? Group.fromJson(json['group']) : null,
players = json['players'] != null
? (json['players'] as List)
.map((playerJson) => Player.fromJson(playerJson))
.toList()
.map((playerJson) => Player.fromJson(playerJson))
.toList()
: null,
group = json['group'] != null ? Group.fromJson(json['group']) : null,
winner = json['winner'] != null ? Player.fromJson(json['winner']) : null;
notes = json['notes'];
/// Converts the Match instance to a JSON object.
Map<String, dynamic> toJson() => {
'id': id,
'createdAt': createdAt.toIso8601String(),
'name': name,
'players': players?.map((player) => player.toJson()).toList(),
'game': game?.toJson(),
'group': group?.toJson(),
'winner': winner?.toJson(),
'players': players?.map((player) => player.toJson()).toList(),
'notes': notes,
};
}