Skip to content

Commit

Permalink
Improve storm scores screen
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Feb 3, 2025
1 parent fc5eac0 commit 3aa8d18
Showing 1 changed file with 111 additions and 90 deletions.
201 changes: 111 additions & 90 deletions lib/src/view/puzzle/storm_dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class _Body extends ConsumerWidget {

final LightUser user;

static const EdgeInsets _statCardPadding = EdgeInsets.symmetric(horizontal: 8.0, vertical: 10.0);

@override
Widget build(BuildContext context, WidgetRef ref) {
final stormDashboard = ref.watch(stormDashboardProvider(user.id));
Expand All @@ -49,105 +51,124 @@ class _Body extends ConsumerWidget {
return const Center(child: Text('Could not load dashboard.'));
}
final dateFormat = DateFormat('MMMM d, yyyy');
return SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
return ListView(
children: [
Padding(
padding: Styles.sectionTopPadding.add(Styles.horizontalBodyPadding),
child: StatCardRow([
StatCard(
backgroundColor: LichessColors.brag.withValues(alpha: 0.5),
context.l10n.stormAllTime,
value: data.highScore.allTime.toString(),
valueFontSize: 26,
contentPadding: _statCardPadding,
),
StatCard(
context.l10n.stormThisMonth,
value: data.highScore.month.toString(),
valueFontSize: 22,
contentPadding: _statCardPadding,
),
]),
),
Padding(
padding: Styles.horizontalBodyPadding,
child: StatCardRow([
StatCard(
context.l10n.stormThisWeek,
value: data.highScore.week.toString(),
valueFontSize: 22,
contentPadding: _statCardPadding,
),
StatCard(
context.l10n.today,
value: data.highScore.day.toString(),
valueFontSize: 22,
contentPadding: _statCardPadding,
),
]),
),
if (data.dayHighscores.isNotEmpty) ...[
Padding(
padding: Styles.sectionTopPadding.add(Styles.horizontalBodyPadding),
child: StatCardRow([
StatCard(context.l10n.stormAllTime, value: data.highScore.allTime.toString()),
StatCard(context.l10n.stormThisMonth, value: data.highScore.month.toString()),
]),
padding: Styles.bodySectionPadding,
child: Text(context.l10n.stormBestRunOfDay, style: Styles.sectionTitle),
),
Padding(
padding: Styles.sectionTopPadding.add(Styles.horizontalBodyPadding),
child: StatCardRow([
StatCard(context.l10n.stormThisWeek, value: data.highScore.week.toString()),
StatCard(context.l10n.today, value: data.highScore.day.toString()),
]),
),
if (data.dayHighscores.isNotEmpty) ...[
Padding(
padding: Styles.bodySectionPadding,
child: Text(context.l10n.stormBestRunOfDay, style: Styles.sectionTitle),
padding: Styles.horizontalBodyPadding,
child: Table(
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [
TableRow(
children: [
Text(textAlign: TextAlign.center, context.l10n.stormScore),
Text(textAlign: TextAlign.center, context.l10n.stormTime),
Text(textAlign: TextAlign.center, context.l10n.stormHighestSolved),
Text(textAlign: TextAlign.center, context.l10n.stormRuns),
],
),
],
),
Padding(
padding: Styles.horizontalBodyPadding,
child: Table(
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [
TableRow(
children: [
Text(textAlign: TextAlign.center, context.l10n.stormScore),
Text(textAlign: TextAlign.center, context.l10n.stormTime),
Text(textAlign: TextAlign.center, context.l10n.stormHighestSolved),
Text(textAlign: TextAlign.center, context.l10n.stormRuns),
],
),
ListView.builder(
primary: false,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: data.dayHighscores.length * 2,
itemBuilder: (context, index) {
if (index.isEven) {
// Date row
final entryIndex = index ~/ 2;
return ColoredBox(
color: LichessColors.grey.withValues(alpha: 0.23),
child: Padding(
padding: Styles.horizontalBodyPadding,
child: Text(
dateFormat.format(data.dayHighscores[entryIndex].day),
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
],
),
),
Flexible(
child: ListView.builder(
itemCount: data.dayHighscores.length * 2,
itemBuilder: (context, index) {
if (index.isEven) {
// Date row
final entryIndex = index ~/ 2;
return ColoredBox(
color: LichessColors.grey.withValues(alpha: 0.23),
child: Padding(
padding: Styles.horizontalBodyPadding,
child: Text(
dateFormat.format(data.dayHighscores[entryIndex].day),
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
);
} else {
// Data row
final entryIndex = (index - 1) ~/ 2;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
child: Table(
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
);
} else {
// Data row
final entryIndex = (index - 1) ~/ 2;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
child: Table(
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [
TableRow(
children: [
TableRow(
children: [
Text(
textAlign: TextAlign.center,
data.dayHighscores[entryIndex].score.toString(),
style: TextStyle(
color: context.lichessColors.brag,
fontWeight: FontWeight.bold,
),
),
Text(
textAlign: TextAlign.center,
'${data.dayHighscores[entryIndex].time}s',
),
Text(
textAlign: TextAlign.center,
data.dayHighscores[entryIndex].highest.toString(),
),
Text(
textAlign: TextAlign.center,
data.dayHighscores[entryIndex].runs.toString(),
),
],
Text(
textAlign: TextAlign.center,
data.dayHighscores[entryIndex].score.toString(),
style: TextStyle(
color: context.lichessColors.brag,
fontWeight: FontWeight.bold,
),
),
Text(
textAlign: TextAlign.center,
'${data.dayHighscores[entryIndex].time}s',
),
Text(
textAlign: TextAlign.center,
data.dayHighscores[entryIndex].highest.toString(),
),
Text(
textAlign: TextAlign.center,
data.dayHighscores[entryIndex].runs.toString(),
),
],
),
);
}
},
),
),
] else
Center(child: Text(context.l10n.mobilePuzzleStormNothingToShow)),
],
),
],
),
);
}
},
),
] else
Center(child: Text(context.l10n.mobilePuzzleStormNothingToShow)),
],
);
},
error: (e, s) {
Expand Down

0 comments on commit 3aa8d18

Please sign in to comment.