Fix: Winner gets resetted, if player gets removed from the game

This commit is contained in:
2026-03-07 17:03:52 +01:00
parent 664af7ffee
commit 4bcb10df81
2 changed files with 8 additions and 11 deletions

View File

@@ -315,6 +315,9 @@ class _CreateMatchViewState extends State<CreateMatchView> {
matchId: widget.match!.id, matchId: widget.match!.id,
playerId: player.id, playerId: player.id,
); );
if (widget.match!.winner?.id == player.id) {
updatedMatch.winner = null;
}
} }
} }

View File

@@ -40,15 +40,12 @@ class MatchDetailView extends StatefulWidget {
class _MatchDetailViewState extends State<MatchDetailView> { class _MatchDetailViewState extends State<MatchDetailView> {
late final AppDatabase db; late final AppDatabase db;
late Player? currentWinner;
late Match match; late Match match;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
db = Provider.of<AppDatabase>(context, listen: false); db = Provider.of<AppDatabase>(context, listen: false);
currentWinner = widget.match.winner;
match = widget.match; match = widget.match;
} }
@@ -184,7 +181,7 @@ class _MatchDetailViewState extends State<MatchDetailView> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
/// TODO: Implement different ruleset results display /// TODO: Implement different ruleset results display
if (currentWinner != null) ...[ if (match.winner != null) ...[
Text( Text(
loc.winner, loc.winner,
style: const TextStyle( style: const TextStyle(
@@ -193,13 +190,11 @@ class _MatchDetailViewState extends State<MatchDetailView> {
), ),
), ),
Text( Text(
currentWinner!.name, match.winner!.name,
style: TextStyle( style: const TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: match.winner != null color: CustomTheme.primaryColor,
? CustomTheme.primaryColor
: CustomTheme.textColor,
), ),
), ),
] else ...[ ] else ...[
@@ -239,7 +234,7 @@ class _MatchDetailViewState extends State<MatchDetailView> {
text: loc.enter_results, text: loc.enter_results,
icon: Icons.emoji_events, icon: Icons.emoji_events,
onPressed: () async { onPressed: () async {
currentWinner = await Navigator.push( match.winner = await Navigator.push(
context, context,
adaptivePageRoute( adaptivePageRoute(
fullscreenDialog: true, fullscreenDialog: true,
@@ -252,7 +247,6 @@ class _MatchDetailViewState extends State<MatchDetailView> {
), ),
), ),
); );
match.winner = currentWinner;
}, },
), ),
], ],