fix: refresh problem
This commit is contained in:
@@ -8,8 +8,6 @@ import 'package:tallee/core/custom_theme.dart';
|
|||||||
import 'package:tallee/core/enums.dart';
|
import 'package:tallee/core/enums.dart';
|
||||||
import 'package:tallee/data/db/database.dart';
|
import 'package:tallee/data/db/database.dart';
|
||||||
import 'package:tallee/data/models/match.dart';
|
import 'package:tallee/data/models/match.dart';
|
||||||
import 'package:tallee/data/models/score_entry.dart';
|
|
||||||
import 'package:tallee/data/models/team.dart';
|
|
||||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/create_match_view.dart';
|
import 'package:tallee/presentation/views/main_menu/match_view/create_match/create_match_view.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/match_view/match_result_view.dart';
|
import 'package:tallee/presentation/views/main_menu/match_view/match_result_view.dart';
|
||||||
@@ -48,17 +46,11 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
|||||||
|
|
||||||
late Match localMatch;
|
late Match localMatch;
|
||||||
|
|
||||||
late List<Team> localTeams;
|
|
||||||
|
|
||||||
late Map<String, ScoreEntry?> localScores;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
db = Provider.of<AppDatabase>(context, listen: false);
|
db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
localMatch = widget.match;
|
localMatch = widget.match;
|
||||||
localScores = localMatch.scores;
|
|
||||||
localTeams = localMatch.teams ?? [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -175,7 +167,7 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
|||||||
crossAxisAlignment: WrapCrossAlignment.start,
|
crossAxisAlignment: WrapCrossAlignment.start,
|
||||||
spacing: 12,
|
spacing: 12,
|
||||||
runSpacing: 8,
|
runSpacing: 8,
|
||||||
children: localMatch.teams!.map((team) {
|
children: (localMatch.teams ?? []).map((team) {
|
||||||
return TeamCard(team: team);
|
return TeamCard(team: team);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
@@ -313,30 +305,38 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
|||||||
final ruleset = localMatch.game.ruleset;
|
final ruleset = localMatch.game.ruleset;
|
||||||
|
|
||||||
if (localMatch.mvp.isNotEmpty || localMatch.mvt.isNotEmpty) {
|
if (localMatch.mvp.isNotEmpty || localMatch.mvt.isNotEmpty) {
|
||||||
// Single Winner / Loser
|
// Single winner/loser, multiple winner
|
||||||
final mvps = localMatch.isTeamMatch
|
final names = localMatch.isTeamMatch
|
||||||
? localMatch.mvt
|
? localMatch.mvt.map((t) => t.name).toList()
|
||||||
: localMatch.mvp;
|
: localMatch.mvp.map((p) => p.name).toList();
|
||||||
final mvpName = ruleset == Ruleset.multipleWinners
|
final mvpNames = names.length == 1 ? names.first : names.join(', ');
|
||||||
? mvps.map((party) => party.name).join(', ')
|
|
||||||
: mvps.first.name;
|
final label = ruleset == Ruleset.singleWinner
|
||||||
|
? loc.winner
|
||||||
|
: ruleset == Ruleset.singleLoser
|
||||||
|
? loc.loser
|
||||||
|
: loc.winners;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Text(
|
Text(
|
||||||
ruleset == Ruleset.singleWinner ? loc.winner : loc.loser,
|
label,
|
||||||
style: const TextStyle(fontSize: 16, color: CustomTheme.textColor),
|
style: const TextStyle(fontSize: 16, color: CustomTheme.textColor),
|
||||||
),
|
),
|
||||||
Text(
|
SizedBox(
|
||||||
mvpName,
|
width: 200,
|
||||||
|
child: Text(
|
||||||
|
mvpNames,
|
||||||
|
textAlign: TextAlign.end,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: CustomTheme.primaryColor,
|
color: CustomTheme.primaryColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
// No result entered yet
|
// No result yet
|
||||||
return [
|
return [
|
||||||
Text(
|
Text(
|
||||||
loc.no_results_entered_yet,
|
loc.no_results_entered_yet,
|
||||||
@@ -375,7 +375,8 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
|||||||
List<(String, int)> namedScores = [];
|
List<(String, int)> namedScores = [];
|
||||||
|
|
||||||
if (localMatch.isTeamMatch) {
|
if (localMatch.isTeamMatch) {
|
||||||
for (var team in localTeams) {
|
final teams = localMatch.teams ?? [];
|
||||||
|
for (var team in teams) {
|
||||||
int score = team.score ?? 0;
|
int score = team.score ?? 0;
|
||||||
namedScores.add((team.name, score));
|
namedScores.add((team.name, score));
|
||||||
}
|
}
|
||||||
@@ -388,8 +389,9 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
|||||||
namedScores.sort((a, b) => a.$2.compareTo(b.$2));
|
namedScores.sort((a, b) => a.$2.compareTo(b.$2));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
final scores = localMatch.scores;
|
||||||
for (var player in localMatch.players) {
|
for (var player in localMatch.players) {
|
||||||
int score = localScores[player.id]?.score ?? 0;
|
int score = scores[player.id]?.score ?? 0;
|
||||||
namedScores.add((player.name, score));
|
namedScores.add((player.name, score));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,16 +479,19 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Die Methode selbst:
|
|
||||||
Future<void> updateScoresForCurrentMatch() async {
|
Future<void> updateScoresForCurrentMatch() async {
|
||||||
if (widget.match.isTeamMatch) {
|
if (localMatch.isTeamMatch) {
|
||||||
final teams = await db.teamDao.getTeamsByMatchId(matchId: localMatch.id);
|
final teams = await db.teamDao.getTeamsByMatchId(matchId: localMatch.id);
|
||||||
if (mounted) setState(() => localTeams = teams);
|
setState(() {
|
||||||
|
localMatch = localMatch.copyWith(teams: teams);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
final scores = await db.scoreEntryDao.getAllMatchScores(
|
final scores = await db.scoreEntryDao.getAllMatchScores(
|
||||||
matchId: localMatch.id,
|
matchId: localMatch.id,
|
||||||
);
|
);
|
||||||
if (mounted) setState(() => localScores = scores);
|
setState(() {
|
||||||
|
localMatch = localMatch.copyWith(scores: scores);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ class _MatchResultViewState extends State<MatchResultView> {
|
|||||||
// Show player selection
|
// Show player selection
|
||||||
if (rulesetSupportsPlayerSelection())
|
if (rulesetSupportsPlayerSelection())
|
||||||
if (ruleset == Ruleset.multipleWinners)
|
if (ruleset == Ruleset.multipleWinners)
|
||||||
|
// TODO: Implement view for teams
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
|||||||
Reference in New Issue
Block a user