Skip to content

Commit

Permalink
feat: add rank change widget
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharlock10 committed Apr 21, 2024
1 parent fdbeaa7 commit 57f2ba0
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/data_classes/players/player_timed_stats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Expand Down
120 changes: 115 additions & 5 deletions lib/screens/home/home_timed_stats_rank_change.dart
Original file line number Diff line number Diff line change
@@ -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 }

Expand All @@ -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;
Expand All @@ -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,
);
}
}

0 comments on commit 57f2ba0

Please sign in to comment.