From 57f2ba0eeafcbdece4c837ead3d8fc5233194dcc Mon Sep 17 00:00:00 2001 From: Tushar Jain Date: Mon, 22 Apr 2024 01:18:39 +0530 Subject: [PATCH] feat: add rank change widget --- .../players/player_timed_stats.dart | 2 +- .../home/home_timed_stats_rank_change.dart | 120 +++++++++++++++++- 2 files changed, 116 insertions(+), 6 deletions(-) diff --git a/lib/data_classes/players/player_timed_stats.dart b/lib/data_classes/players/player_timed_stats.dart index 2d81eaa..5738d2e 100644 --- a/lib/data_classes/players/player_timed_stats.dart +++ b/lib/data_classes/players/player_timed_stats.dart @@ -9,7 +9,7 @@ enum TimedStatsType { days1, days7, days30 } abstract class TimedStatsValues { static const durationNames = { - TimedStatsType.days1: "Today", + TimedStatsType.days1: "last 24 hours", TimedStatsType.days7: "Last 7 Days", TimedStatsType.days30: "Last 30 Days", }; diff --git a/lib/screens/home/home_timed_stats_rank_change.dart b/lib/screens/home/home_timed_stats_rank_change.dart index 381858a..a8e18be 100644 --- a/lib/screens/home/home_timed_stats_rank_change.dart +++ b/lib/screens/home/home_timed_stats_rank_change.dart @@ -1,7 +1,9 @@ import "package:flutter/material.dart"; +import "package:flutter_feather_icons/flutter_feather_icons.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; enum RankChangeType { noChange, tpChange, rankChange } @@ -16,16 +18,20 @@ class HomeTimedStatsRankChange extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final baseRanks = ref.read(providers.baseRanks).baseRanks; final playerNotifier = providers.players(playerId); final timedStats = ref.watch(playerNotifier.select((_) => _.timedStats)); + // Variables + final theme = Theme.of(context); + final tpText = theme.textTheme.labelSmall; + final tpTextLarge = theme.textTheme.displayMedium?.copyWith(fontSize: 20); + // Hooks final rankChangeType = useMemoized( () { final rankedStart = timedStats?.rankedStart; final rankedEnd = timedStats?.rankedEnd; - // print("RANKED START : $rankedStart"); - // print("RANKED END : $rankedEnd"); if (rankedStart == null || rankedEnd == null) { return RankChangeType.noChange; @@ -42,13 +48,117 @@ class HomeTimedStatsRankChange extends HookConsumerWidget { [timedStats], ); + final startRank = useMemoized( + () { + final rank = timedStats?.rankedStart?.rank; + if (rank == null) return null; + + return baseRanks[rank]; + }, + [timedStats], + ); + + final endRank = useMemoized( + () { + final rank = timedStats?.rankedEnd?.rank; + if (rank == null) return null; + + return baseRanks[rank]; + }, + [timedStats], + ); + if (rankChangeType == RankChangeType.rankChange) { - return const Text("Rank Change"); + return Row( + children: [ + if (startRank != null) + Column( + children: [ + widgets.FastImage( + imageUrl: startRank.rankIconUrl, + height: 36, + width: 36, + ), + Text( + "${timedStats!.rankedStart!.points} TP", + style: tpText, + ), + ], + ), + const Column( + children: [ + Padding( + padding: EdgeInsets.symmetric(horizontal: 5), + child: Icon( + FeatherIcons.arrowRight, + color: Colors.grey, + size: 22, + ), + ), + SizedBox(height: 20), + ], + ), + if (endRank != null) + Column( + children: [ + widgets.FastImage( + imageUrl: endRank.rankIconUrl, + height: 36, + width: 36, + ), + Text( + "${timedStats!.rankedEnd!.points} TP", + style: tpText, + ), + ], + ), + ], + ); } + if (rankChangeType == RankChangeType.tpChange) { - return const Text("TP Change"); + return Row( + children: [ + if (endRank != null) + widgets.FastImage( + imageUrl: endRank.rankIconUrl, + height: 36, + width: 36, + ), + const SizedBox(width: 5), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text("TP Changed", style: tpText), + Row( + children: [ + Text( + "${timedStats!.rankedStart!.points}", + style: tpTextLarge, + ), + const Padding( + padding: EdgeInsets.symmetric(horizontal: 7.5), + child: Icon( + FeatherIcons.arrowRight, + color: Colors.grey, + size: 16, + ), + ), + Text( + "${timedStats.rankedEnd!.points}", + style: tpTextLarge, + ), + ], + ), + ], + ), + ], + ); } - return const Text("No change"); + return Text( + "Play Ranked to view\nyour rank changes here", + style: tpText, + ); } }