Merge branch 'development' into feature/6-statisticsview-erstellen
# Conflicts: # lib/presentation/views/main_menu/statistics_view.dart
This commit is contained in:
@@ -20,13 +20,16 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
result.map((row) async {
|
||||
final group = await db.groupGameDao.getGroupOfGame(gameId: row.id);
|
||||
final players = await db.playerGameDao.getPlayersOfGame(gameId: row.id);
|
||||
final winner = row.winnerId != null
|
||||
? await db.playerDao.getPlayerById(playerId: row.winnerId!)
|
||||
: null;
|
||||
return Game(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
group: group,
|
||||
players: players,
|
||||
createdAt: row.createdAt,
|
||||
winner: row.winnerId,
|
||||
winner: winner,
|
||||
);
|
||||
}),
|
||||
);
|
||||
@@ -45,13 +48,17 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
if (await db.groupGameDao.gameHasGroup(gameId: gameId)) {
|
||||
group = await db.groupGameDao.getGroupOfGame(gameId: gameId);
|
||||
}
|
||||
Player? winner;
|
||||
if (result.winnerId != null) {
|
||||
winner = await db.playerDao.getPlayerById(playerId: result.winnerId!);
|
||||
}
|
||||
|
||||
return Game(
|
||||
id: result.id,
|
||||
name: result.name,
|
||||
players: players,
|
||||
group: group,
|
||||
winner: result.winnerId,
|
||||
winner: winner,
|
||||
createdAt: result.createdAt,
|
||||
);
|
||||
}
|
||||
@@ -64,7 +71,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
GameTableCompanion.insert(
|
||||
id: game.id,
|
||||
name: game.name,
|
||||
winnerId: Value(game.winner),
|
||||
winnerId: Value(game.winner?.id),
|
||||
createdAt: game.createdAt,
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
@@ -100,7 +107,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
id: game.id,
|
||||
name: game.name,
|
||||
createdAt: game.createdAt,
|
||||
winnerId: Value(game.winner),
|
||||
winnerId: Value(game.winner?.id),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
|
||||
@@ -9,7 +9,7 @@ class Game {
|
||||
final String name;
|
||||
final List<Player>? players;
|
||||
final Group? group;
|
||||
final String? winner;
|
||||
final Player? winner;
|
||||
|
||||
Game({
|
||||
String? id,
|
||||
@@ -17,7 +17,7 @@ class Game {
|
||||
required this.name,
|
||||
this.players,
|
||||
this.group,
|
||||
this.winner = '',
|
||||
this.winner,
|
||||
}) : id = id ?? const Uuid().v4(),
|
||||
createdAt = createdAt ?? clock.now();
|
||||
|
||||
@@ -37,7 +37,7 @@ class Game {
|
||||
.toList()
|
||||
: null,
|
||||
group = json['group'] != null ? Group.fromJson(json['group']) : null,
|
||||
winner = json['winner'] ?? '';
|
||||
winner = json['winner'] != null ? Player.fromJson(json['winner']) : null;
|
||||
|
||||
/// Converts the Game instance to a JSON object.
|
||||
Map<String, dynamic> toJson() => {
|
||||
@@ -46,6 +46,6 @@ class Game {
|
||||
'name': name,
|
||||
'players': players?.map((player) => player.toJson()).toList(),
|
||||
'group': group?.toJson(),
|
||||
'winner': winner,
|
||||
'winner': winner?.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,14 +127,14 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
// Getting the winners
|
||||
for (var game in games) {
|
||||
final winner = game.winner;
|
||||
if (winner != null && winner.isNotEmpty) {
|
||||
final index = winCounts.indexWhere((entry) => entry.$1 == winner);
|
||||
if (winner != null) {
|
||||
final index = winCounts.indexWhere((entry) => entry.$1 == winner.id);
|
||||
// -1 means winner not found in winCounts
|
||||
if (index != -1) {
|
||||
final current = winCounts[index].$2;
|
||||
winCounts[index] = (winner, current + 1);
|
||||
winCounts[index] = (winner.id, current + 1);
|
||||
} else {
|
||||
winCounts.add((winner, 1));
|
||||
winCounts.add((winner.id, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user