From 0ab87d460c3804294292396988734cb23bea1e68 Mon Sep 17 00:00:00 2001 From: Tushar Jain Date: Tue, 26 Mar 2024 03:50:04 +0530 Subject: [PATCH] feat: add player timed stats in home screen --- lib/providers/players.dart | 3 -- lib/screens/home/home.dart | 6 +++ lib/screens/home/home_player_timed_stats.dart | 40 +++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 lib/screens/home/home_player_timed_stats.dart diff --git a/lib/providers/players.dart b/lib/providers/players.dart index c6292d6..83cd6c9 100644 --- a/lib/providers/players.dart +++ b/lib/providers/players.dart @@ -151,9 +151,6 @@ class _PlayersNotifier extends ChangeNotifier { data_classes.TimedStatsType.days1, playerId, ); - print("TIMED :: ${timedStats!.totalMatches}"); - print("TIMED TOTAL :: ${timedStats!.totalStats.kills}"); - print("TIMED AVG :: ${timedStats!.averageStats.kills}"); } if (!forceUpdate) isPlayerMatchesLoading = false; diff --git a/lib/screens/home/home.dart b/lib/screens/home/home.dart index bf2d1db..138e325 100644 --- a/lib/screens/home/home.dart +++ b/lib/screens/home/home.dart @@ -4,6 +4,7 @@ import "package:hooks_riverpod/hooks_riverpod.dart"; import "package:paladinsedge/constants/index.dart" as constants; import "package:paladinsedge/providers/index.dart" as providers; import "package:paladinsedge/screens/home/home_favourite_friends.dart"; +import "package:paladinsedge/screens/home/home_player_timed_stats.dart"; import "package:paladinsedge/screens/home/home_queue_chart.dart"; import "package:paladinsedge/screens/home/home_queue_details.dart"; import "package:paladinsedge/screens/home/home_top_matches.dart"; @@ -95,6 +96,11 @@ class Home extends HookConsumerWidget { ), if (!isGuest) const SizedBox(height: 20), if (!isGuest) const HomeFavouriteFriends(), + if (player != null) + Padding( + padding: const EdgeInsets.only(top: 20), + child: HomePlayerTimedStats(playerId: player.playerId), + ), const SizedBox(height: 20), const HomeTopMatches(), const SizedBox(height: 20), diff --git a/lib/screens/home/home_player_timed_stats.dart b/lib/screens/home/home_player_timed_stats.dart new file mode 100644 index 0000000..d76d2ac --- /dev/null +++ b/lib/screens/home/home_player_timed_stats.dart @@ -0,0 +1,40 @@ +import "package:flutter/material.dart"; +import "package:flutter_hooks/flutter_hooks.dart"; +import "package:hooks_riverpod/hooks_riverpod.dart"; +import "package:paladinsedge/providers/index.dart" as providers; +import "package:paladinsedge/widgets/index.dart" as widgets; + +class HomePlayerTimedStats extends HookConsumerWidget { + final String playerId; + + const HomePlayerTimedStats({ + required this.playerId, + Key? key, + }) : super(key: key); + + @override + Widget build(BuildContext context, WidgetRef ref) { + // Providers + final playerNotifier = providers.players(playerId); + final playerProvider = ref.read(playerNotifier); + final timedStats = ref.watch(playerNotifier.select((_) => _.timedStats)); + final isPlayerMatchesLoading = + ref.watch(playerNotifier.select((_) => _.isPlayerMatchesLoading)); + + // Effects + useEffect( + () { + playerProvider.getPlayerMatches(); + + return null; + }, + [], + ); + + return timedStats == null || isPlayerMatchesLoading + ? const widgets.LoadingIndicator(size: 18) + : Card( + child: Text("Average Kills : ${timedStats.averageStats.kills}"), + ); + } +}