-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add player timed stats in home screen
- Loading branch information
1 parent
3906c0e
commit 0ab87d4
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"), | ||
); | ||
} | ||
} |