Skip to content

Commit

Permalink
feat: add player timed stats in home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharlock10 committed Mar 25, 2024
1 parent 3906c0e commit 0ab87d4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
3 changes: 0 additions & 3 deletions lib/providers/players.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions lib/screens/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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),
Expand Down
40 changes: 40 additions & 0 deletions lib/screens/home/home_player_timed_stats.dart
Original file line number Diff line number Diff line change
@@ -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}"),
);
}
}

0 comments on commit 0ab87d4

Please sign in to comment.