6 Commits

Author SHA1 Message Date
73c8865eb5 Removed todo
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 38s
Pull Request Pipeline / lint (pull_request) Successful in 44s
2026-03-07 22:48:57 +01:00
9d2b6a0286 Adapted getTemporaryGame method 2026-03-07 22:47:28 +01:00
588b5053e8 typo 2026-03-07 22:46:21 +01:00
0597b21ac1 Added condition 2026-03-07 22:45:55 +01:00
a846e4d7ea Removed dead code 2026-03-07 22:44:49 +01:00
16aecffdbe Change var name 2026-03-07 22:43:24 +01:00
2 changed files with 34 additions and 54 deletions

View File

@@ -24,7 +24,7 @@ class CreateMatchView extends StatefulWidget {
const CreateMatchView({ const CreateMatchView({
super.key, super.key,
this.onWinnerChanged, this.onWinnerChanged,
this.match, this.matchToEdit,
this.onMatchUpdated, this.onMatchUpdated,
}); });
@@ -35,7 +35,7 @@ class CreateMatchView extends StatefulWidget {
final void Function(Match)? onMatchUpdated; final void Function(Match)? onMatchUpdated;
/// An optional match to prefill the fields /// An optional match to prefill the fields
final Match? match; final Match? matchToEdit;
@override @override
State<CreateMatchView> createState() => _CreateMatchViewState(); State<CreateMatchView> createState() => _CreateMatchViewState();
@@ -56,12 +56,6 @@ class _CreateMatchViewState extends State<CreateMatchView> {
/// List of all players from the database /// List of all players from the database
List<Player> playerList = []; List<Player> playerList = [];
/// List of players filtered based on the selected group
/// If a group is selected, this list contains all players from [playerList]
/// who are not members of the selected group. If no group is selected,
/// this list is identical to [playerList].
/*List<Player> filteredPlayerList = [];*/
/// The currently selected group /// The currently selected group
Group? selectedGroup; Group? selectedGroup;
@@ -92,7 +86,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
playerList = result[1] as List<Player>; playerList = result[1] as List<Player>;
// If a match is provided, prefill the fields // If a match is provided, prefill the fields
if (widget.match != null) { if (widget.matchToEdit != null) {
prefillMatchDetails(); prefillMatchDetails();
} }
}); });
@@ -119,10 +113,10 @@ class _CreateMatchViewState extends State<CreateMatchView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final loc = AppLocalizations.of(context); final loc = AppLocalizations.of(context);
final buttonText = widget.match != null final buttonText = widget.matchToEdit != null
? loc.save_changes ? loc.save_changes
: loc.create_match; : loc.create_match;
final viewTitle = widget.match != null final viewTitle = widget.matchToEdit != null
? loc.edit_match ? loc.edit_match
: loc.create_new_match; : loc.create_new_match;
@@ -237,15 +231,16 @@ class _CreateMatchViewState extends State<CreateMatchView> {
/// - A ruleset is selected AND /// - A ruleset is selected AND
/// - Either a group is selected OR at least 2 players are selected /// - Either a group is selected OR at least 2 players are selected
bool _enableCreateGameButton() { bool _enableCreateGameButton() {
return (selectedGroup != null || (selectedPlayers.length > 1)); return (selectedGroup != null ||
(selectedPlayers.length > 1) && selectedGameIndex != -1);
} }
// If a match was provied to the view, it updates the match in the database // If a match was provided to the view, it updates the match in the database
// and navigates back to the previous screen. // and navigates back to the previous screen.
// If no match was provided, it creates a new match in the database and // If no match was provided, it creates a new match in the database and
// navigates to the MatchResultView for the newly created match. // navigates to the MatchResultView for the newly created match.
void buttonNavigation(BuildContext context) async { void buttonNavigation(BuildContext context) async {
if (widget.match != null) { if (widget.matchToEdit != null) {
await updateMatch(); await updateMatch();
if (context.mounted) { if (context.mounted) {
Navigator.pop(context); Navigator.pop(context);
@@ -275,51 +270,51 @@ class _CreateMatchViewState extends State<CreateMatchView> {
final tempGame = await getTemporaryGame(); final tempGame = await getTemporaryGame();
final updatedMatch = Match( final updatedMatch = Match(
id: widget.match!.id, id: widget.matchToEdit!.id,
name: _matchNameController.text.isEmpty name: _matchNameController.text.isEmpty
? (hintText ?? '') ? (hintText ?? '')
: _matchNameController.text.trim(), : _matchNameController.text.trim(),
group: selectedGroup, group: selectedGroup,
players: selectedPlayers, players: selectedPlayers,
game: tempGame, game: tempGame,
winner: widget.match!.winner, winner: widget.matchToEdit!.winner,
createdAt: widget.match!.createdAt, createdAt: widget.matchToEdit!.createdAt,
endedAt: widget.match!.endedAt, endedAt: widget.matchToEdit!.endedAt,
notes: widget.match!.notes, notes: widget.matchToEdit!.notes,
); );
if (widget.match!.name != updatedMatch.name) { if (widget.matchToEdit!.name != updatedMatch.name) {
await db.matchDao.updateMatchName( await db.matchDao.updateMatchName(
matchId: widget.match!.id, matchId: widget.matchToEdit!.id,
newName: updatedMatch.name, newName: updatedMatch.name,
); );
} }
if (widget.match!.group?.id != updatedMatch.group?.id) { if (widget.matchToEdit!.group?.id != updatedMatch.group?.id) {
await db.matchDao.updateMatchGroup( await db.matchDao.updateMatchGroup(
matchId: widget.match!.id, matchId: widget.matchToEdit!.id,
newGroupId: updatedMatch.group?.id, newGroupId: updatedMatch.group?.id,
); );
} }
// Add players who are in updatedMatch but not in the original match // Add players who are in updatedMatch but not in the original match
for (var player in updatedMatch.players) { for (var player in updatedMatch.players) {
if (!widget.match!.players.any((p) => p.id == player.id)) { if (!widget.matchToEdit!.players.any((p) => p.id == player.id)) {
await db.playerMatchDao.addPlayerToMatch( await db.playerMatchDao.addPlayerToMatch(
matchId: widget.match!.id, matchId: widget.matchToEdit!.id,
playerId: player.id, playerId: player.id,
); );
} }
} }
// Remove players who are in the original match but not in updatedMatch // Remove players who are in the original match but not in updatedMatch
for (var player in widget.match!.players) { for (var player in widget.matchToEdit!.players) {
if (!updatedMatch.players.any((p) => p.id == player.id)) { if (!updatedMatch.players.any((p) => p.id == player.id)) {
await db.playerMatchDao.removePlayerFromMatch( await db.playerMatchDao.removePlayerFromMatch(
matchId: widget.match!.id, matchId: widget.matchToEdit!.id,
playerId: player.id, playerId: player.id,
); );
if (widget.match!.winner?.id == player.id) { if (widget.matchToEdit!.winner?.id == player.id) {
updatedMatch.winner = null; updatedMatch.winner = null;
} }
} }
@@ -350,19 +345,6 @@ class _CreateMatchViewState extends State<CreateMatchView> {
Future<Game> getTemporaryGame() async { Future<Game> getTemporaryGame() async {
Game? game; Game? game;
// No game is selected
if (selectedGameIndex == -1) {
// Use the first game as default if none selected
final selectedGame = games[0];
game = Game(
name: selectedGame.$1,
description: selectedGame.$2,
ruleset: selectedGame.$3,
color: GameColor.blue,
icon: '',
);
} else {
// Use the selected game from the list
final selectedGame = games[selectedGameIndex]; final selectedGame = games[selectedGameIndex];
game = Game( game = Game(
name: selectedGame.$1, name: selectedGame.$1,
@@ -371,15 +353,14 @@ class _CreateMatchViewState extends State<CreateMatchView> {
color: GameColor.blue, color: GameColor.blue,
icon: '', icon: '',
); );
}
// Add the game to the database if it doesn't exist
await db.gameDao.addGame(game: game); await db.gameDao.addGame(game: game);
return game; return game;
} }
// If a match was provided to the view, this method prefills the input fields // If a match was provided to the view, this method prefills the input fields
void prefillMatchDetails() { void prefillMatchDetails() {
final match = widget.match!; final match = widget.matchToEdit!;
_matchNameController.text = match.name; _matchNameController.text = match.name;
selectedPlayers = match.players; selectedPlayers = match.players;

View File

@@ -142,7 +142,6 @@ class _MatchDetailViewState extends State<MatchDetailView> {
const Icon(Icons.group), const Icon(Icons.group),
const SizedBox(width: 8), const SizedBox(width: 8),
Text( Text(
// TODO: Update after DB changes
'${match.group!.name}${getExtraPlayerCount(match)}', '${match.group!.name}${getExtraPlayerCount(match)}',
style: const TextStyle(fontWeight: FontWeight.bold), style: const TextStyle(fontWeight: FontWeight.bold),
), ),
@@ -222,7 +221,7 @@ class _MatchDetailViewState extends State<MatchDetailView> {
adaptivePageRoute( adaptivePageRoute(
fullscreenDialog: true, fullscreenDialog: true,
builder: (context) => CreateMatchView( builder: (context) => CreateMatchView(
match: match, matchToEdit: match,
onMatchUpdated: onMatchUpdated, onMatchUpdated: onMatchUpdated,
), ),
), ),