47 Commits

Author SHA1 Message Date
1c0fb9f3ab Merge branch 'development' into bug/73-Fehlende-Info-in-CreateGroupView
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m19s
Pull Request Pipeline / lint (pull_request) Successful in 2m21s
2025-12-31 16:41:26 +01:00
27916456db Merge pull request 'Fehler bei Match-Erstellung' (#104) from bug/102-fehler-bei-match-erstellung into development
Reviewed-on: #104
Reviewed-by: Mathis Kirchner <mathis.kirchner.mk@gmail.com>
2025-12-30 20:17:18 +00:00
c1789458e0 Added tests for bug causing behaviour
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m6s
Pull Request Pipeline / lint (pull_request) Successful in 2m8s
2025-12-30 20:56:39 +01:00
e19f696714 Fixed tests with adding players and groups to database on setup
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m6s
Pull Request Pipeline / lint (pull_request) Successful in 2m11s
2025-12-30 18:51:57 +01:00
9cb35dc4a1 Updated comments
Some checks failed
Pull Request Pipeline / test (pull_request) Failing after 2m9s
Pull Request Pipeline / lint (pull_request) Successful in 2m9s
2025-12-30 18:45:28 +01:00
b8b65c4ca1 Removed lines that added the group and players to the db again in addMatch()
Some checks failed
Pull Request Pipeline / lint (pull_request) Successful in 2m9s
Pull Request Pipeline / test (pull_request) Failing after 2m19s
2025-12-30 18:23:15 +01:00
356cb1fb43 Updated insert mode to fix problem with replacing existing player match connections 2025-12-30 18:21:39 +01:00
4c8896d2d9 Merge pull request 'Fehlende Aktualisierung in MatchView' (#101) from bug/95-fehlende-aktualisierung-in-matchview into development
Reviewed-on: #101
Reviewed-by: Mathis Kirchner <mathis.kirchner.mk@gmail.com>
2025-12-30 16:49:02 +00:00
31c8598222 Made cleaner version
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m4s
Pull Request Pipeline / lint (pull_request) Successful in 2m6s
2025-12-29 19:28:47 +01:00
884680d329 Merge branch 'development' into bug/95-fehlende-aktualisierung-in-matchview
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m3s
Pull Request Pipeline / lint (pull_request) Successful in 2m6s
2025-12-29 19:23:11 +01:00
5ae569f2e7 Fixed updating error
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m1s
Pull Request Pipeline / lint (pull_request) Successful in 2m3s
2025-12-29 19:16:25 +01:00
37d6ad81fd Merge pull request 'ChooseGroupView zeigt keine Group entspricht der Suche, obwohl nur Gruppen leer' (#98) from bug/94-choosegroupview-zeigt-keine-group-entspricht-der-suche-obwohl-nur-gruppen-leer into development
Reviewed-on: #98
Reviewed-by: Mathis Kirchner <mathis.kirchner.mk@gmail.com>
2025-12-29 17:47:11 +00:00
cea6c36407 Merge branch 'development' into bug/94-choosegroupview-zeigt-keine-group-entspricht-der-suche-obwohl-nur-gruppen-leer
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m3s
Pull Request Pipeline / lint (pull_request) Successful in 2m5s
2025-12-29 17:45:00 +00:00
1b300faea9 Merge pull request '"Per Player" entfernen' (#99) from enhancement/93-per-player-entfernen into development
Reviewed-on: #99
Reviewed-by: gelbeinhalb <spam@yannick-weigert.de>
Reviewed-by: Mathis Kirchner <mathis.kirchner.mk@gmail.com>
2025-12-29 17:41:50 +00:00
dac5cc8a89 Hab leider nur von Wand bis Tapete gedacht
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m2s
Pull Request Pipeline / lint (pull_request) Successful in 2m5s
2025-12-29 18:37:44 +01:00
bafbde7d03 Merge remote-tracking branch 'origin/bug/94-choosegroupview-zeigt-keine-group-entspricht-der-suche-obwohl-nur-gruppen-leer' into bug/94-choosegroupview-zeigt-keine-group-entspricht-der-suche-obwohl-nur-gruppen-leer 2025-12-29 18:35:26 +01:00
fdea594a1e Merge branch 'development' into bug/94-choosegroupview-zeigt-keine-group-entspricht-der-suche-obwohl-nur-gruppen-leer
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m33s
Pull Request Pipeline / lint (pull_request) Successful in 2m36s
2025-12-29 17:28:50 +00:00
856ce43c49 Updated statistics title
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m32s
Pull Request Pipeline / lint (pull_request) Successful in 2m37s
2025-12-29 18:28:06 +01:00
5c8b93072f Merge branch 'development' into bug/94-choosegroupview-zeigt-keine-group-entspricht-der-suche-obwohl-nur-gruppen-leer 2025-12-29 18:25:30 +01:00
94fdd7026d Merge pull request 'FutureBuilder-/Skeleton-/Futurelogik verbessern' (#90) from enhancement/80-FutureBuilder-Logik-bei-Interaktion-mit-DB-verbessern into development
Reviewed-on: #90
Reviewed-by: gelbeinhalb <spam@yannick-weigert.de>
Reviewed-by: Felix Kirchner <felix.kirchner.fk@gmail.com>
2025-12-29 17:21:49 +00:00
966f7caa54 Fixed info message
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m8s
Pull Request Pipeline / lint (pull_request) Successful in 2m13s
2025-12-29 18:19:29 +01:00
88bea48956 Merge remote-tracking branch 'origin/development' into enhancement/80-FutureBuilder-Logik-bei-Interaktion-mit-DB-verbessern
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m13s
Pull Request Pipeline / lint (pull_request) Successful in 2m17s
# Conflicts:
#	lib/presentation/views/main_menu/match_view/match_view.dart
2025-12-29 18:19:03 +01:00
a2e66b9c80 Merge pull request 'Letztes Gametile nicht komplett sichtbar' (#96) from bug/79-Letztes-Gametile-in-der-GamesView-ist-nicht-lesbar into development
Reviewed-on: #96
Reviewed-by: gelbeinhalb <spam@yannick-weigert.de>
2025-12-25 09:55:31 +00:00
d7a006dd87 fixed last gametile not visible
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m8s
Pull Request Pipeline / lint (pull_request) Successful in 2m8s
2025-12-24 23:51:34 +01:00
12856342a8 remove dots after sentences
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m1s
Pull Request Pipeline / lint (pull_request) Successful in 2m4s
2025-12-24 22:53:17 +01:00
b0a5145490 move setState to include match loading and sorting in MatchView 2025-12-24 13:14:31 +01:00
7a80c1a792 adjust heightFactor for empty game state in home view
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m5s
Pull Request Pipeline / lint (pull_request) Successful in 2m7s
2025-12-24 13:08:25 +01:00
c73f37507f put isLoading in existing setState and move mounted check up
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m4s
Pull Request Pipeline / lint (pull_request) Successful in 2m7s
2025-12-24 13:05:49 +01:00
1e730cebe6 wrap isLoading into mounted and setState
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m8s
Pull Request Pipeline / lint (pull_request) Successful in 2m9s
2025-12-24 13:01:40 +01:00
7eb25221d7 add mounted check before calling setState in match_view 2025-12-24 13:01:16 +01:00
f9722bc762 wrap isLoading = false in a mounted check and setState call 2025-12-24 13:01:05 +01:00
f2917a6813 removed empty line 2025-12-24 13:00:38 +01:00
b29cd6dff4 remove double quotes
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m15s
Pull Request Pipeline / lint (pull_request) Successful in 2m21s
2025-12-24 12:54:05 +01:00
1d92084da6 fix rangeerror when only 1 or less matches exist
Some checks failed
Pull Request Pipeline / test (pull_request) Successful in 2m21s
Pull Request Pipeline / lint (pull_request) Failing after 2m34s
2025-12-24 12:53:37 +01:00
7732c6ceb9 remove futurebuilder from match view and refactor
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m10s
Pull Request Pipeline / lint (pull_request) Successful in 2m10s
2025-12-23 23:17:27 +01:00
a747d91c5d refactor group loading into reusable method loadGroups and call it after adding a group 2025-12-23 23:16:57 +01:00
06a9c0cd84 remove futurebuilder from player selection and refactor 2025-12-23 22:59:01 +01:00
9ad5c4ad6f remove futurebuilder from groups view and refactor 2025-12-23 22:58:49 +01:00
9b3d61e5b0 remove futurebuilder from playerselection and refactor 2025-12-23 22:36:11 +01:00
df0a5207c2 add const
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m5s
Pull Request Pipeline / lint (pull_request) Successful in 2m22s
2025-12-21 20:01:48 +01:00
4f0a1eec6d refactor
Some checks failed
Pull Request Pipeline / test (pull_request) Successful in 2m6s
Pull Request Pipeline / lint (pull_request) Failing after 2m6s
2025-12-21 19:50:34 +01:00
24b60bb18b added minimumSkeletonDuration constant and changed future logic 2025-12-21 19:46:59 +01:00
c8532adfde changed skeleton duration logic in statistics view and refactored 2025-12-21 15:52:02 +01:00
76186787e7 changed futurebuilder logic in player selection 2025-12-21 15:51:24 +01:00
f05114a99e removed futurebuilder logic in groups_view 2025-12-21 15:50:39 +01:00
d96494f608 Changed futurebuilder logic in groups_view 2025-12-21 15:50:24 +01:00
0eaf3d251b added constant minimumSkeletonDuration 2025-12-21 15:49:58 +01:00
15 changed files with 395 additions and 375 deletions

2
lib/core/constants.dart Normal file
View File

@@ -0,0 +1,2 @@
/// Minimum duration of all app skeletons
Duration minimumSkeletonDuration = const Duration(milliseconds: 250);

View File

@@ -21,7 +21,7 @@ class GroupMatchDao extends DatabaseAccessor<AppDatabase>
} }
await into(groupMatchTable).insert( await into(groupMatchTable).insert(
GroupMatchTableCompanion.insert(groupId: groupId, matchId: matchId), GroupMatchTableCompanion.insert(groupId: groupId, matchId: matchId),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrIgnore,
); );
} }

View File

@@ -65,8 +65,9 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
); );
} }
/// Adds a new [Match] to the database. /// Adds a new [Match] to the database. Also adds players and group
/// Also adds associated players and group if they exist. /// associations. This method assumes that the players and groups added to
/// this match are already present in the database.
Future<void> addMatch({required Match match}) async { Future<void> addMatch({required Match match}) async {
await db.transaction(() async { await db.transaction(() async {
await into(matchTable).insert( await into(matchTable).insert(
@@ -80,7 +81,6 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
); );
if (match.players != null) { if (match.players != null) {
await db.playerDao.addPlayersAsList(players: match.players!);
for (final p in match.players ?? []) { for (final p in match.players ?? []) {
await db.playerMatchDao.addPlayerToMatch( await db.playerMatchDao.addPlayerToMatch(
matchId: match.id, matchId: match.id,
@@ -90,7 +90,6 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
} }
if (match.group != null) { if (match.group != null) {
await db.groupDao.addGroup(group: match.group!);
await db.groupMatchDao.addGroupToMatch( await db.groupMatchDao.addGroupToMatch(
matchId: match.id, matchId: match.id,
groupId: match.group!.id, groupId: match.group!.id,
@@ -102,6 +101,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
/// Adds multiple [Match]s to the database in a batch operation. /// Adds multiple [Match]s to the database in a batch operation.
/// Also adds associated players and groups if they exist. /// Also adds associated players and groups if they exist.
/// If the [matches] list is empty, the method returns immediately. /// If the [matches] list is empty, the method returns immediately.
/// This Method should only be used to import matches from a different device.
Future<void> addMatchAsList({required List<Match> matches}) async { Future<void> addMatchAsList({required List<Match> matches}) async {
if (matches.isEmpty) return; if (matches.isEmpty) return;
await db.transaction(() async { await db.transaction(() async {
@@ -186,7 +186,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
matchId: match.id, matchId: match.id,
playerId: p.id, playerId: p.id,
), ),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrIgnore,
); );
} }
} }
@@ -204,7 +204,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
playerId: m.id, playerId: m.id,
groupId: match.group!.id, groupId: match.group!.id,
), ),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrIgnore,
); );
} }
} }
@@ -221,7 +221,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
matchId: match.id, matchId: match.id,
groupId: match.group!.id, groupId: match.group!.id,
), ),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrIgnore,
); );
} }
} }

View File

@@ -18,7 +18,7 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
}) async { }) async {
await into(playerMatchTable).insert( await into(playerMatchTable).insert(
PlayerMatchTableCompanion.insert(playerId: playerId, matchId: matchId), PlayerMatchTableCompanion.insert(playerId: playerId, matchId: matchId),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrIgnore,
); );
} }
@@ -121,7 +121,7 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
inserts.map( inserts.map(
(c) => into( (c) => into(
playerMatchTable, playerMatchTable,
).insert(c, mode: InsertMode.insertOrReplace), ).insert(c, mode: InsertMode.insertOrIgnore),
), ),
); );
} }

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:game_tracker/core/constants.dart';
import 'package:game_tracker/core/custom_theme.dart'; import 'package:game_tracker/core/custom_theme.dart';
import 'package:game_tracker/data/db/database.dart'; import 'package:game_tracker/data/db/database.dart';
import 'package:game_tracker/data/dto/group.dart'; import 'package:game_tracker/data/dto/group.dart';
@@ -18,15 +19,15 @@ class GroupsView extends StatefulWidget {
} }
class _GroupsViewState extends State<GroupsView> { class _GroupsViewState extends State<GroupsView> {
late Future<List<Group>> _allGroupsFuture;
late final AppDatabase db; late final AppDatabase db;
late List<Group> loadedGroups;
bool isLoading = true;
final player = Player(name: 'Skeleton Player'); List<Group> groups = List.filled(
late final List<Group> skeletonData = List.filled(
7, 7,
Group( Group(
name: 'Skeleton Match', name: 'Skeleton Group',
members: [player, player, player, player, player, player], members: List.filled(6, Player(name: 'Skeleton Player')),
), ),
); );
@@ -34,10 +35,7 @@ class _GroupsViewState extends State<GroupsView> {
void initState() { void initState() {
super.initState(); super.initState();
db = Provider.of<AppDatabase>(context, listen: false); db = Provider.of<AppDatabase>(context, listen: false);
_allGroupsFuture = Future.delayed( loadGroups();
const Duration(milliseconds: 250),
() => db.groupDao.getAllGroups(),
);
} }
@override @override
@@ -47,50 +45,30 @@ class _GroupsViewState extends State<GroupsView> {
body: Stack( body: Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
FutureBuilder<List<Group>>( AppSkeleton(
future: _allGroupsFuture, enabled: isLoading,
builder: child: Visibility(
(BuildContext context, AsyncSnapshot<List<Group>> snapshot) { visible: groups.isNotEmpty,
if (snapshot.hasError) { replacement: const Center(
return const Center( child: TopCenteredMessage(
child: TopCenteredMessage( icon: Icons.info,
icon: Icons.report, title: 'Info',
title: 'Error', message: 'No groups created yet',
message: 'Group data couldn\'t\nbe loaded', ),
), ),
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: groups.length + 1,
itemBuilder: (BuildContext context, int index) {
if (index == groups.length) {
return SizedBox(
height: MediaQuery.paddingOf(context).bottom - 20,
); );
} }
if (snapshot.connectionState == ConnectionState.done && return GroupTile(group: groups[index]);
(!snapshot.hasData || snapshot.data!.isEmpty)) {
return const Center(
child: TopCenteredMessage(
icon: Icons.info,
title: 'Info',
message: 'No groups created yet',
),
);
}
final bool isLoading =
snapshot.connectionState == ConnectionState.waiting;
final List<Group> groups =
isLoading ? skeletonData : (snapshot.data ?? [])
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
return AppSkeleton(
enabled: isLoading,
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: groups.length + 1,
itemBuilder: (BuildContext context, int index) {
if (index == groups.length) {
return SizedBox(
height: MediaQuery.paddingOf(context).bottom - 20,
);
}
return GroupTile(group: groups[index]);
},
),
);
}, },
),
),
), ),
Positioned( Positioned(
bottom: MediaQuery.paddingOf(context).bottom, bottom: MediaQuery.paddingOf(context).bottom,
@@ -107,7 +85,7 @@ class _GroupsViewState extends State<GroupsView> {
), ),
); );
setState(() { setState(() {
_allGroupsFuture = db.groupDao.getAllGroups(); loadGroups();
}); });
}, },
), ),
@@ -116,4 +94,22 @@ class _GroupsViewState extends State<GroupsView> {
), ),
); );
} }
void loadGroups() {
Future.wait([
db.groupDao.getAllGroups(),
Future.delayed(minimumSkeletonDuration),
]).then((results) {
loadedGroups = results[0] as List<Group>;
setState(() {
groups = loadedGroups
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
});
if (mounted) {
setState(() {
isLoading = false;
});
}
});
}
} }

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:game_tracker/core/constants.dart';
import 'package:game_tracker/data/db/database.dart'; import 'package:game_tracker/data/db/database.dart';
import 'package:game_tracker/data/dto/group.dart'; import 'package:game_tracker/data/dto/group.dart';
import 'package:game_tracker/data/dto/match.dart'; import 'package:game_tracker/data/dto/match.dart';
@@ -18,12 +19,11 @@ class HomeView extends StatefulWidget {
} }
class _HomeViewState extends State<HomeView> { class _HomeViewState extends State<HomeView> {
late Future<int> _matchCountFuture;
late Future<int> _groupCountFuture;
late Future<List<Match>> _recentMatchesFuture;
bool isLoading = true; bool isLoading = true;
int matchCount = 0;
late final List<Match> skeletonData = List.filled( int groupCount = 0;
List<Match> loadedRecentMatches = [];
List<Match> recentMatches = List.filled(
2, 2,
Match( Match(
name: 'Skeleton Match', name: 'Skeleton Match',
@@ -39,19 +39,28 @@ class _HomeViewState extends State<HomeView> {
); );
@override @override
initState() { void initState() {
super.initState(); super.initState();
final db = Provider.of<AppDatabase>(context, listen: false); final db = Provider.of<AppDatabase>(context, listen: false);
_matchCountFuture = db.matchDao.getMatchCount();
_groupCountFuture = db.groupDao.getGroupCount();
_recentMatchesFuture = db.matchDao.getAllMatches();
Future.wait([ Future.wait([
_matchCountFuture, db.matchDao.getMatchCount(),
_groupCountFuture, db.groupDao.getGroupCount(),
_recentMatchesFuture, db.matchDao.getAllMatches(),
]).then((_) async { Future.delayed(minimumSkeletonDuration),
await Future.delayed(const Duration(milliseconds: 250)); ]).then((results) {
matchCount = results[0] as int;
groupCount = results[1] as int;
loadedRecentMatches = results[2] as List<Match>;
recentMatches =
(loadedRecentMatches
..sort((a, b) => b.createdAt.compareTo(a.createdAt)))
.take(2)
.toList();
if (loadedRecentMatches.length < 2) {
recentMatches.add(
Match(name: 'Dummy Match', winner: null, group: null, players: null),
);
}
if (mounted) { if (mounted) {
setState(() { setState(() {
isLoading = false; isLoading = false;
@@ -65,6 +74,7 @@ class _HomeViewState extends State<HomeView> {
return LayoutBuilder( return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) { builder: (BuildContext context, BoxConstraints constraints) {
return AppSkeleton( return AppSkeleton(
fixLayoutBuilder: true,
enabled: isLoading, enabled: isLoading,
child: SingleChildScrollView( child: SingleChildScrollView(
child: Column( child: Column(
@@ -73,38 +83,20 @@ class _HomeViewState extends State<HomeView> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
FutureBuilder<int>( QuickInfoTile(
future: _matchCountFuture, width: constraints.maxWidth * 0.45,
builder: (context, snapshot) { height: constraints.maxHeight * 0.15,
final int count = (snapshot.hasData) title: 'Matches',
? snapshot.data! icon: Icons.groups_rounded,
: 0; value: matchCount,
return QuickInfoTile(
width: constraints.maxWidth * 0.45,
height: constraints.maxHeight * 0.15,
title: 'Matches',
icon: Icons.groups_rounded,
value: count,
);
},
), ),
SizedBox(width: constraints.maxWidth * 0.05), SizedBox(width: constraints.maxWidth * 0.05),
FutureBuilder<int>( QuickInfoTile(
future: _groupCountFuture, width: constraints.maxWidth * 0.45,
builder: (context, snapshot) { height: constraints.maxHeight * 0.15,
final int count = title: 'Groups',
(snapshot.connectionState == ConnectionState.done && icon: Icons.groups_rounded,
snapshot.hasData) value: groupCount,
? snapshot.data!
: 0;
return QuickInfoTile(
width: constraints.maxWidth * 0.45,
height: constraints.maxHeight * 0.15,
title: 'Groups',
icon: Icons.groups_rounded,
value: count,
);
},
), ),
], ],
), ),
@@ -116,80 +108,48 @@ class _HomeViewState extends State<HomeView> {
icon: Icons.timer, icon: Icons.timer,
content: Padding( content: Padding(
padding: const EdgeInsets.symmetric(horizontal: 40.0), padding: const EdgeInsets.symmetric(horizontal: 40.0),
child: FutureBuilder( child: Visibility(
future: _recentMatchesFuture, visible: !isLoading && loadedRecentMatches.isNotEmpty,
builder: replacement: const Center(
( heightFactor: 12,
BuildContext context, child: Text('No recent games available'),
AsyncSnapshot<List<Match>> snapshot, ),
) { child: Column(
if (snapshot.hasError) { mainAxisAlignment: MainAxisAlignment.start,
return const Center( crossAxisAlignment: CrossAxisAlignment.start,
heightFactor: 4, children: [
child: Text( MatchTile(
'Error while loading recent matches.', matchTitle: recentMatches[0].name,
), game: 'Winner',
); ruleset: 'Ruleset',
} players: _getPlayerText(recentMatches[0]),
final List<Match> matches = winner: recentMatches[0].winner == null
(isLoading ? 'Match in progress...'
? skeletonData : recentMatches[0].winner!.name,
: (snapshot.data ?? []) ),
..sort( const Padding(
(a, b) => b.createdAt.compareTo( padding: EdgeInsets.symmetric(vertical: 8.0),
a.createdAt, child: Divider(),
), ),
)) if (loadedRecentMatches.length > 1) ...[
.take(2) MatchTile(
.toList(); matchTitle: recentMatches[1].name,
if (matches.isNotEmpty) { game: 'Winner',
return Column( ruleset: 'Ruleset',
mainAxisAlignment: MainAxisAlignment.start, players: _getPlayerText(recentMatches[1]),
crossAxisAlignment: CrossAxisAlignment.start, winner: recentMatches[1].winner == null
children: [ ? 'Game in progress...'
MatchTile( : recentMatches[1].winner!.name,
matchTitle: matches[0].name, ),
game: 'Winner', const SizedBox(height: 8),
ruleset: 'Ruleset', ] else ...[
players: _getPlayerText(matches[0]), const Center(
winner: matches[0].winner == null heightFactor: 5.35,
? 'Match in progress...' child: Text('No second game available'),
: matches[0].winner!.name, ),
), ],
const Padding( ],
padding: EdgeInsets.symmetric( ),
vertical: 8.0,
),
child: Divider(),
),
if (matches.length > 1) ...[
MatchTile(
matchTitle: matches[1].name,
game: 'Winner',
ruleset: 'Ruleset',
players: _getPlayerText(matches[1]),
winner: matches[1].winner == null
? 'Game in progress...'
: matches[1].winner!.name,
),
const SizedBox(height: 8),
] else ...[
const Center(
heightFactor: 4,
child: Text(
'No second game available.',
),
),
],
],
);
} else {
return const Center(
heightFactor: 12,
child: Text('No recent games available.'),
);
}
},
), ),
), ),
), ),
@@ -199,7 +159,6 @@ class _HomeViewState extends State<HomeView> {
title: 'Quick Create', title: 'Quick Create',
icon: Icons.add_box_rounded, icon: Icons.add_box_rounded,
content: Column( content: Column(
spacing: 8,
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,

View File

@@ -74,10 +74,18 @@ class _ChooseGroupViewState extends State<ChooseGroupView> {
Expanded( Expanded(
child: Visibility( child: Visibility(
visible: filteredGroups.isNotEmpty, visible: filteredGroups.isNotEmpty,
replacement: const TopCenteredMessage( replacement: Visibility(
icon: Icons.info, visible: widget.groups.isNotEmpty,
title: 'Info', replacement: const TopCenteredMessage(
message: 'There is no group matching your search', icon: Icons.info,
title: 'Info',
message: 'You have no groups created yet',
),
child: const TopCenteredMessage(
icon: Icons.info,
title: 'Info',
message: 'There is no group matching your search',
),
), ),
child: ListView.builder( child: ListView.builder(
padding: const EdgeInsets.only(bottom: 85), padding: const EdgeInsets.only(bottom: 85),

View File

@@ -28,12 +28,6 @@ class _CreateMatchViewState extends State<CreateMatchView> {
/// Reference to the app database /// Reference to the app database
late final AppDatabase db; late final AppDatabase db;
/// Futures to load all groups and players from the database
late Future<List<Group>> _allGroupsFuture;
/// Future to load all players from the database
late Future<List<Player>> _allPlayersFuture;
/// Controller for the game name input field /// Controller for the game name input field
final TextEditingController _gameNameController = TextEditingController(); final TextEditingController _gameNameController = TextEditingController();
@@ -107,14 +101,13 @@ class _CreateMatchViewState extends State<CreateMatchView> {
db = Provider.of<AppDatabase>(context, listen: false); db = Provider.of<AppDatabase>(context, listen: false);
_allGroupsFuture = db.groupDao.getAllGroups(); Future.wait([
_allPlayersFuture = db.playerDao.getAllPlayers(); db.groupDao.getAllGroups(),
db.playerDao.getAllPlayers(),
Future.wait([_allGroupsFuture, _allPlayersFuture]).then((result) async { ]).then((result) async {
groupsList = result[0] as List<Group>; groupsList = result[0] as List<Group>;
playerList = result[1] as List<Player>; playerList = result[1] as List<Player>;
}); });
filteredPlayerList = List.from(playerList); filteredPlayerList = List.from(playerList);
} }

View File

@@ -38,6 +38,13 @@ class _GameResultViewState extends State<GameResultView> {
return Scaffold( return Scaffold(
backgroundColor: CustomTheme.backgroundColor, backgroundColor: CustomTheme.backgroundColor,
appBar: AppBar( appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: () {
widget.onWinnerChanged?.call();
Navigator.of(context).pop();
},
),
backgroundColor: CustomTheme.backgroundColor, backgroundColor: CustomTheme.backgroundColor,
scrolledUnderElevation: 0, scrolledUnderElevation: 0,
title: Text( title: Text(

View File

@@ -2,6 +2,7 @@ import 'dart:core' hide Match;
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:game_tracker/core/constants.dart';
import 'package:game_tracker/core/custom_theme.dart'; import 'package:game_tracker/core/custom_theme.dart';
import 'package:game_tracker/data/db/database.dart'; import 'package:game_tracker/data/db/database.dart';
import 'package:game_tracker/data/dto/group.dart'; import 'package:game_tracker/data/dto/group.dart';
@@ -23,16 +24,16 @@ class MatchView extends StatefulWidget {
} }
class _MatchViewState extends State<MatchView> { class _MatchViewState extends State<MatchView> {
late Future<List<Match>> _gameListFuture;
late final AppDatabase db; late final AppDatabase db;
bool isLoading = true;
late final List<Match> skeletonData = List.filled( List<Match> matches = List.filled(
4, 4,
Match( Match(
name: 'Skeleton Gamename', name: 'Skeleton Gamename',
group: Group( group: Group(
name: 'Groupname', name: 'Groupname',
members: List.generate(5, (index) => Player(name: 'Player')), members: List.filled(5, Player(name: 'Player')),
), ),
winner: Player(name: 'Player'), winner: Player(name: 'Player'),
players: [Player(name: 'Player')], players: [Player(name: 'Player')],
@@ -43,10 +44,7 @@ class _MatchViewState extends State<MatchView> {
void initState() { void initState() {
super.initState(); super.initState();
db = Provider.of<AppDatabase>(context, listen: false); db = Provider.of<AppDatabase>(context, listen: false);
_gameListFuture = Future.delayed( loadGames();
const Duration(milliseconds: 250),
() => db.matchDao.getAllMatches(),
);
} }
@override @override
@@ -56,67 +54,44 @@ class _MatchViewState extends State<MatchView> {
body: Stack( body: Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
FutureBuilder<List<Match>>( AppSkeleton(
future: _gameListFuture, enabled: isLoading,
builder: child: Visibility(
(BuildContext context, AsyncSnapshot<List<Match>> snapshot) { visible: matches.isNotEmpty,
if (snapshot.hasError) { replacement: const Center(
return const Center( child: TopCenteredMessage(
child: TopCenteredMessage( icon: Icons.report,
icon: Icons.report, title: 'Info',
title: 'Error', message: 'No games created yet',
message: 'Game data could not be loaded', ),
), ),
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: matches.length + 1,
itemBuilder: (BuildContext context, int index) {
if (index == matches.length) {
return SizedBox(
height: MediaQuery.paddingOf(context).bottom - 80,
); );
} }
if (snapshot.connectionState == ConnectionState.done && return GameHistoryTile(
(!snapshot.hasData || snapshot.data!.isEmpty)) { onTap: () async {
return const Center( Navigator.push(
child: TopCenteredMessage( context,
icon: Icons.report, CupertinoPageRoute(
title: 'Info', fullscreenDialog: true,
message: 'No games created yet', builder: (context) => GameResultView(
), match: matches[index],
); onWinnerChanged: loadGames,
} ),
final bool isLoading = ),
snapshot.connectionState == ConnectionState.waiting; );
final List<Match> matches = },
(isLoading ? skeletonData : (snapshot.data ?? []) match: matches[index],
..sort(
(a, b) => b.createdAt.compareTo(a.createdAt),
))
.toList();
return AppSkeleton(
enabled: isLoading,
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: matches.length + 1,
itemBuilder: (BuildContext context, int index) {
if (index == matches.length) {
return SizedBox(
height: MediaQuery.paddingOf(context).bottom - 80,
);
}
return GameHistoryTile(
onTap: () async {
Navigator.push(
context,
CupertinoPageRoute(
fullscreenDialog: true,
builder: (context) => GameResultView(
match: matches[index],
onWinnerChanged: refreshGameList,
),
),
);
},
match: matches[index],
);
},
),
); );
}, },
),
),
), ),
Positioned( Positioned(
bottom: MediaQuery.paddingOf(context).bottom, bottom: MediaQuery.paddingOf(context).bottom,
@@ -128,7 +103,7 @@ class _MatchViewState extends State<MatchView> {
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => builder: (context) =>
CreateMatchView(onWinnerChanged: refreshGameList), CreateMatchView(onWinnerChanged: loadGames),
), ),
); );
}, },
@@ -139,9 +114,19 @@ class _MatchViewState extends State<MatchView> {
); );
} }
void refreshGameList() { void loadGames() {
setState(() { Future.wait([
_gameListFuture = db.matchDao.getAllMatches(); db.matchDao.getAllMatches(),
Future.delayed(minimumSkeletonDuration),
]).then((results) {
if (mounted) {
setState(() {
final loadedMatches = results[0] as List<Match>;
matches = loadedMatches
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
isLoading = false;
});
}
}); });
} }
} }

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:game_tracker/core/constants.dart';
import 'package:game_tracker/data/db/database.dart'; import 'package:game_tracker/data/db/database.dart';
import 'package:game_tracker/data/dto/match.dart'; import 'package:game_tracker/data/dto/match.dart';
import 'package:game_tracker/data/dto/player.dart'; import 'package:game_tracker/data/dto/player.dart';
@@ -14,8 +15,6 @@ class StatisticsView extends StatefulWidget {
} }
class _StatisticsViewState extends State<StatisticsView> { class _StatisticsViewState extends State<StatisticsView> {
late Future<List<Match>> _matchesFuture;
late Future<List<Player>> _playersFuture;
List<(String, int)> winCounts = List.filled(6, ('Skeleton Player', 1)); List<(String, int)> winCounts = List.filled(6, ('Skeleton Player', 1));
List<(String, int)> matchCounts = List.filled(6, ('Skeleton Player', 1)); List<(String, int)> matchCounts = List.filled(6, ('Skeleton Player', 1));
List<(String, double)> winRates = List.filled(6, ('Skeleton Player', 1)); List<(String, double)> winRates = List.filled(6, ('Skeleton Player', 1));
@@ -25,11 +24,12 @@ class _StatisticsViewState extends State<StatisticsView> {
void initState() { void initState() {
super.initState(); super.initState();
final db = Provider.of<AppDatabase>(context, listen: false); final db = Provider.of<AppDatabase>(context, listen: false);
_matchesFuture = db.matchDao.getAllMatches();
_playersFuture = db.playerDao.getAllPlayers();
Future.wait([_matchesFuture, _playersFuture]).then((results) async { Future.wait([
await Future.delayed(const Duration(milliseconds: 250)); db.matchDao.getAllMatches(),
db.playerDao.getAllPlayers(),
Future.delayed(minimumSkeletonDuration),
]).then((results) async {
final matches = results[0] as List<Match>; final matches = results[0] as List<Match>;
final players = results[1] as List<Player>; final players = results[1] as List<Player>;
winCounts = _calculateWinsForAllPlayers(matches, players); winCounts = _calculateWinsForAllPlayers(matches, players);
@@ -60,7 +60,7 @@ class _StatisticsViewState extends State<StatisticsView> {
SizedBox(height: constraints.maxHeight * 0.01), SizedBox(height: constraints.maxHeight * 0.01),
StatisticsTile( StatisticsTile(
icon: Icons.sports_score, icon: Icons.sports_score,
title: 'Wins per Player', title: 'Wins',
width: constraints.maxWidth * 0.95, width: constraints.maxWidth * 0.95,
values: winCounts, values: winCounts,
itemCount: 3, itemCount: 3,
@@ -69,7 +69,7 @@ class _StatisticsViewState extends State<StatisticsView> {
SizedBox(height: constraints.maxHeight * 0.02), SizedBox(height: constraints.maxHeight * 0.02),
StatisticsTile( StatisticsTile(
icon: Icons.percent, icon: Icons.percent,
title: 'Winrate per Player', title: 'Winrate',
width: constraints.maxWidth * 0.95, width: constraints.maxWidth * 0.95,
values: winRates, values: winRates,
itemCount: 5, itemCount: 5,
@@ -78,7 +78,7 @@ class _StatisticsViewState extends State<StatisticsView> {
SizedBox(height: constraints.maxHeight * 0.02), SizedBox(height: constraints.maxHeight * 0.02),
StatisticsTile( StatisticsTile(
icon: Icons.casino, icon: Icons.casino,
title: 'Match per Player', title: 'Amount of Matches',
width: constraints.maxWidth * 0.95, width: constraints.maxWidth * 0.95,
values: matchCounts, values: matchCounts,
itemCount: 10, itemCount: 10,

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:game_tracker/core/constants.dart';
import 'package:game_tracker/core/custom_theme.dart'; import 'package:game_tracker/core/custom_theme.dart';
import 'package:game_tracker/data/db/database.dart'; import 'package:game_tracker/data/db/database.dart';
import 'package:game_tracker/data/dto/player.dart'; import 'package:game_tracker/data/dto/player.dart';
@@ -29,6 +30,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
List<Player> selectedPlayers = []; List<Player> selectedPlayers = [];
List<Player> suggestedPlayers = []; List<Player> suggestedPlayers = [];
List<Player> allPlayers = []; List<Player> allPlayers = [];
bool isLoading = true;
late final TextEditingController _searchBarController = late final TextEditingController _searchBarController =
TextEditingController(); TextEditingController();
late final AppDatabase db; late final AppDatabase db;
@@ -42,41 +44,44 @@ class _PlayerSelectionState extends State<PlayerSelection> {
void initState() { void initState() {
super.initState(); super.initState();
db = Provider.of<AppDatabase>(context, listen: false); db = Provider.of<AppDatabase>(context, listen: false);
suggestedPlayers = skeletonData;
loadPlayerList(); loadPlayerList();
} }
void loadPlayerList() { void loadPlayerList() {
_allPlayersFuture = Future.delayed( _allPlayersFuture = Future.wait([
const Duration(milliseconds: 250), db.playerDao.getAllPlayers(),
() => db.playerDao.getAllPlayers(), Future.delayed(minimumSkeletonDuration),
); ]).then((results) => results[0] as List<Player>);
suggestedPlayers = skeletonData; if (mounted) {
_allPlayersFuture.then((loadedPlayers) { _allPlayersFuture.then((loadedPlayers) {
setState(() { setState(() {
// If a list of available players is provided, use that list. // If a list of available players is provided, use that list.
if (widget.availablePlayers.isNotEmpty) { if (widget.availablePlayers.isNotEmpty) {
widget.availablePlayers.sort((a, b) => a.name.compareTo(b.name)); widget.availablePlayers.sort((a, b) => a.name.compareTo(b.name));
allPlayers = [...widget.availablePlayers]; allPlayers = [...widget.availablePlayers];
suggestedPlayers = [...allPlayers]; suggestedPlayers = [...allPlayers];
if (widget.initialSelectedPlayers != null) { if (widget.initialSelectedPlayers != null) {
// Ensures that only players available for selection are pre-selected. // Ensures that only players available for selection are pre-selected.
selectedPlayers = widget.initialSelectedPlayers! selectedPlayers = widget.initialSelectedPlayers!
.where( .where(
(p) => widget.availablePlayers.any( (p) => widget.availablePlayers.any(
(available) => available.id == p.id, (available) => available.id == p.id,
), ),
) )
.toList(); .toList();
}
} else {
// Otherwise, use the loaded players from the database.
loadedPlayers.sort((a, b) => a.name.compareTo(b.name));
allPlayers = [...loadedPlayers];
suggestedPlayers = [...loadedPlayers];
} }
} else { isLoading = false;
// Otherwise, use the loaded players from the database. });
loadedPlayers.sort((a, b) => a.name.compareTo(b.name));
allPlayers = [...loadedPlayers];
suggestedPlayers = [...loadedPlayers];
}
}); });
}); }
} }
@override @override
@@ -176,75 +181,44 @@ class _PlayerSelectionState extends State<PlayerSelection> {
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
FutureBuilder( /*
future: _allPlayersFuture,
builder: */
(BuildContext context, AsyncSnapshot<List<Player>> snapshot) { Expanded(
if (snapshot.hasError) { child: AppSkeleton(
return const Center( enabled: isLoading,
child: TopCenteredMessage( child: Visibility(
icon: Icons.report, visible: suggestedPlayers.isNotEmpty,
title: 'Error', replacement: TopCenteredMessage(
message: 'Player data couldn\'t\nbe loaded.', icon: Icons.info,
), title: 'Info',
message: allPlayers.isEmpty
? 'No players created yet'
: (selectedPlayers.length == allPlayers.length)
? 'No more players to add'
: 'No players found with that name',
),
child: ListView.builder(
itemCount: suggestedPlayers.length,
itemBuilder: (BuildContext context, int index) {
return TextIconListTile(
text: suggestedPlayers[index].name,
onPressed: () {
setState(() {
if (!selectedPlayers.contains(
suggestedPlayers[index],
)) {
selectedPlayers.add(suggestedPlayers[index]);
widget.onChanged([...selectedPlayers]);
suggestedPlayers.remove(suggestedPlayers[index]);
}
});
},
); );
} },
bool doneLoading = ),
snapshot.connectionState == ConnectionState.done; ),
bool snapshotDataEmpty = ),
!snapshot.hasData || snapshot.data!.isEmpty;
if (doneLoading &&
(snapshotDataEmpty && allPlayers.isEmpty)) {
return const Center(
child: TopCenteredMessage(
icon: Icons.info,
title: 'Info',
message: 'No players created yet.',
),
);
}
final bool isLoading =
snapshot.connectionState == ConnectionState.waiting;
return Expanded(
child: AppSkeleton(
enabled: isLoading,
child: Visibility(
visible:
(suggestedPlayers.isEmpty && allPlayers.isNotEmpty),
replacement: ListView.builder(
itemCount: suggestedPlayers.length,
itemBuilder: (BuildContext context, int index) {
return TextIconListTile(
text: suggestedPlayers[index].name,
onPressed: () {
setState(() {
if (!selectedPlayers.contains(
suggestedPlayers[index],
)) {
selectedPlayers.add(
suggestedPlayers[index],
);
widget.onChanged([...selectedPlayers]);
suggestedPlayers.remove(
suggestedPlayers[index],
);
}
});
},
);
},
),
child: TopCenteredMessage(
icon: Icons.info,
title: 'Info',
message: (selectedPlayers.length == allPlayers.length)
? 'No more players to add.'
: 'No players found with that name.',
),
),
),
);
},
), ),
], ],
), ),

View File

@@ -23,7 +23,7 @@ void main() {
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23); final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
final fakeClock = Clock(() => fixedDate); final fakeClock = Clock(() => fixedDate);
setUp(() { setUp(() async {
database = AppDatabase( database = AppDatabase(
DatabaseConnection( DatabaseConnection(
NativeDatabase.memory(), NativeDatabase.memory(),
@@ -68,6 +68,16 @@ void main() {
group: testGroup2, group: testGroup2,
); );
}); });
await database.playerDao.addPlayersAsList(
players: [
testPlayer1,
testPlayer2,
testPlayer3,
testPlayer4,
testPlayer5,
],
);
await database.groupDao.addGroupsAsList(groups: [testGroup1, testGroup2]);
}); });
tearDown(() async { tearDown(() async {
await database.close(); await database.close();
@@ -253,7 +263,7 @@ void main() {
expect(matchCount, 0); expect(matchCount, 0);
}); });
test('Checking if match has winner works correclty', () async { test('Checking if match has winner works correctly', () async {
await database.matchDao.addMatch(match: testMatch1); await database.matchDao.addMatch(match: testMatch1);
await database.matchDao.addMatch(match: testMatchOnlyGroup); await database.matchDao.addMatch(match: testMatchOnlyGroup);

View File

@@ -1,5 +1,5 @@
import 'package:clock/clock.dart'; import 'package:clock/clock.dart';
import 'package:drift/drift.dart'; import 'package:drift/drift.dart' hide isNotNull;
import 'package:drift/native.dart'; import 'package:drift/native.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:game_tracker/data/db/database.dart'; import 'package:game_tracker/data/db/database.dart';
@@ -21,7 +21,7 @@ void main() {
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23); final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
final fakeClock = Clock(() => fixedDate); final fakeClock = Clock(() => fixedDate);
setUp(() { setUp(() async {
database = AppDatabase( database = AppDatabase(
DatabaseConnection( DatabaseConnection(
NativeDatabase.memory(), NativeDatabase.memory(),
@@ -53,6 +53,16 @@ void main() {
group: testGroup1, group: testGroup1,
); );
}); });
await database.playerDao.addPlayersAsList(
players: [
testPlayer1,
testPlayer2,
testPlayer3,
testPlayer4,
testPlayer5,
],
);
await database.groupDao.addGroupsAsList(groups: [testGroup1, testGroup2]);
}); });
tearDown(() async { tearDown(() async {
await database.close(); await database.close();
@@ -179,5 +189,33 @@ void main() {
} }
} }
}); });
test('Adding the same group to seperate matches works correctly', () async {
final match1 = Match(name: 'Match 1', group: testGroup1);
final match2 = Match(name: 'Match 2', group: testGroup1);
await Future.wait([
database.matchDao.addMatch(match: match1),
database.matchDao.addMatch(match: match2),
]);
final group1 = await database.groupMatchDao.getGroupOfMatch(
matchId: match1.id,
);
final group2 = await database.groupMatchDao.getGroupOfMatch(
matchId: match2.id,
);
expect(group1, isNotNull);
expect(group2, isNotNull);
final groups = [group1!, group2!];
for (final group in groups) {
expect(group.members.length, testGroup1.members.length);
expect(group.id, testGroup1.id);
expect(group.name, testGroup1.name);
expect(group.createdAt, testGroup1.createdAt);
}
});
}); });
} }

View File

@@ -1,5 +1,5 @@
import 'package:clock/clock.dart'; import 'package:clock/clock.dart';
import 'package:drift/drift.dart'; import 'package:drift/drift.dart' hide isNotNull;
import 'package:drift/native.dart'; import 'package:drift/native.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:game_tracker/data/db/database.dart'; import 'package:game_tracker/data/db/database.dart';
@@ -21,7 +21,7 @@ void main() {
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23); final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
final fakeClock = Clock(() => fixedDate); final fakeClock = Clock(() => fixedDate);
setUp(() { setUp(() async {
database = AppDatabase( database = AppDatabase(
DatabaseConnection( DatabaseConnection(
NativeDatabase.memory(), NativeDatabase.memory(),
@@ -50,6 +50,17 @@ void main() {
players: [testPlayer4, testPlayer5, testPlayer6], players: [testPlayer4, testPlayer5, testPlayer6],
); );
}); });
await database.playerDao.addPlayersAsList(
players: [
testPlayer1,
testPlayer2,
testPlayer3,
testPlayer4,
testPlayer5,
testPlayer6,
],
);
await database.groupDao.addGroup(group: testgroup);
}); });
tearDown(() async { tearDown(() async {
await database.close(); await database.close();
@@ -185,5 +196,42 @@ void main() {
expect(player.createdAt, testPlayer.createdAt); expect(player.createdAt, testPlayer.createdAt);
} }
}); });
test(
'Adding the same player to seperate matches works correctly',
() async {
final playersList = [testPlayer1, testPlayer2, testPlayer3];
final match1 = Match(name: 'Match 1', players: playersList);
final match2 = Match(name: 'Match 2', players: playersList);
await Future.wait([
database.matchDao.addMatch(match: match1),
database.matchDao.addMatch(match: match2),
]);
final players1 = await database.playerMatchDao.getPlayersOfMatch(
matchId: match1.id,
);
final players2 = await database.playerMatchDao.getPlayersOfMatch(
matchId: match2.id,
);
expect(players1, isNotNull);
expect(players2, isNotNull);
expect(
players1!.map((p) => p.id).toList(),
equals(players2!.map((p) => p.id).toList()),
);
expect(
players1.map((p) => p.name).toList(),
equals(players2.map((p) => p.name).toList()),
);
expect(
players1.map((p) => p.createdAt).toList(),
equals(players2.map((p) => p.createdAt).toList()),
);
},
);
}); });
} }