implement changes
This commit is contained in:
@@ -25,6 +25,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||
|
||||
Future.wait([
|
||||
@@ -32,21 +33,25 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
db.playerDao.getAllPlayers(),
|
||||
Future.delayed(minimumSkeletonDuration),
|
||||
]).then((results) async {
|
||||
if (!mounted) return;
|
||||
final matches = results[0] as List<Match>;
|
||||
final players = results[1] as List<Player>;
|
||||
winCounts = _calculateWinsForAllPlayers(matches, players);
|
||||
matchCounts = _calculateMatchAmountsForAllPlayers(matches, players);
|
||||
winCounts = _calculateWinsForAllPlayers(matches, players, context);
|
||||
matchCounts = _calculateMatchAmountsForAllPlayers(
|
||||
matches,
|
||||
players,
|
||||
context,
|
||||
);
|
||||
winRates = computeWinRatePercent(wins: winCounts, matches: matchCounts);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
return LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
return SingleChildScrollView(
|
||||
@@ -69,7 +74,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
children: [
|
||||
StatisticsTile(
|
||||
icon: Icons.sports_score,
|
||||
title: AppLocalizations.of(context).wins,
|
||||
title: loc.wins,
|
||||
width: constraints.maxWidth * 0.95,
|
||||
values: winCounts,
|
||||
itemCount: 3,
|
||||
@@ -78,7 +83,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
SizedBox(height: constraints.maxHeight * 0.02),
|
||||
StatisticsTile(
|
||||
icon: Icons.percent,
|
||||
title: AppLocalizations.of(context).winrate,
|
||||
title: loc.winrate,
|
||||
width: constraints.maxWidth * 0.95,
|
||||
values: winRates,
|
||||
itemCount: 5,
|
||||
@@ -87,7 +92,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
SizedBox(height: constraints.maxHeight * 0.02),
|
||||
StatisticsTile(
|
||||
icon: Icons.casino,
|
||||
title: AppLocalizations.of(context).amount_of_matches,
|
||||
title: loc.amount_of_matches,
|
||||
width: constraints.maxWidth * 0.95,
|
||||
values: matchCounts,
|
||||
itemCount: 10,
|
||||
@@ -97,7 +102,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
),
|
||||
child: TopCenteredMessage(
|
||||
icon: Icons.info,
|
||||
title: AppLocalizations.of(context).info,
|
||||
title: loc.info,
|
||||
message: AppLocalizations.of(
|
||||
context,
|
||||
).no_statistics_available,
|
||||
@@ -118,8 +123,10 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
List<(String, int)> _calculateWinsForAllPlayers(
|
||||
List<Match> matches,
|
||||
List<Player> players,
|
||||
BuildContext context,
|
||||
) {
|
||||
List<(String, int)> winCounts = [];
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
// Getting the winners
|
||||
for (var match in matches) {
|
||||
@@ -150,10 +157,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
final playerId = winCounts[i].$1;
|
||||
final player = players.firstWhere(
|
||||
(p) => p.id == playerId,
|
||||
orElse: () => Player(
|
||||
id: playerId,
|
||||
name: AppLocalizations.of(context).not_available,
|
||||
),
|
||||
orElse: () => Player(id: playerId, name: loc.not_available),
|
||||
);
|
||||
winCounts[i] = (player.name, winCounts[i].$2);
|
||||
}
|
||||
@@ -168,8 +172,10 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
List<(String, int)> _calculateMatchAmountsForAllPlayers(
|
||||
List<Match> matches,
|
||||
List<Player> players,
|
||||
BuildContext context,
|
||||
) {
|
||||
List<(String, int)> matchCounts = [];
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
// Counting matches for each player
|
||||
for (var match in matches) {
|
||||
@@ -215,10 +221,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
final playerId = matchCounts[i].$1;
|
||||
final player = players.firstWhere(
|
||||
(p) => p.id == playerId,
|
||||
orElse: () => Player(
|
||||
id: playerId,
|
||||
name: AppLocalizations.of(context).not_available,
|
||||
),
|
||||
orElse: () => Player(id: playerId, name: loc.not_available),
|
||||
);
|
||||
matchCounts[i] = (player.name, matchCounts[i].$2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user