Skip to content

Offline gym log for Android. No account, no ads, no internet.

Add a 12 month activity calendar

InlitX0428ae2a7476
diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart
index a202a6c..d8ea1aa 100644
--- a/lib/screens/home_screen.dart
+++ b/lib/screens/home_screen.dart
@@ -89,12 +89,19 @@ class HomeScreen extends StatelessWidget {
SoftCard(
radius: 22,
padding: const EdgeInsets.fromLTRB(18, 18, 18, 16),
- child: Heatmap(
- levels: fit.heatmapWeeks,
- firstDay: fit.heatmapWeekDate(0),
- labels: fit.heatmapLabels,
- onTapDay: (i) => showDaySheet(context, fit.heatmapWeekDate(i)),
- ),
+ child: fit.heatmapYear
+ ? HeatmapYear(
+ levels: fit.heatmapShown,
+ firstDay: fit.heatmapShownDate(0),
+ weekdays: fit.heatmapLabels,
+ onTapDay: (i) => showDaySheet(context, fit.heatmapShownDate(i)),
+ )
+ : Heatmap(
+ levels: fit.heatmapWeeks,
+ firstDay: fit.heatmapWeekDate(0),
+ labels: fit.heatmapLabels,
+ onTapDay: (i) => showDaySheet(context, fit.heatmapWeekDate(i)),
+ ),
),
if (fit.showRecommended && recommended.isNotEmpty) ...[
const SizedBox(height: 30),
diff --git a/lib/widgets/charts.dart b/lib/widgets/charts.dart
index 184b93c..8509036 100644
--- a/lib/widgets/charts.dart
+++ b/lib/widgets/charts.dart
@@ -437,11 +437,21 @@ class _TrendPainter extends CustomPainter {
}
class Heatmap extends StatelessWidget {
- const Heatmap({super.key, required this.levels, this.onTapDay, this.firstDay, this.labels = false});
+ const Heatmap({
+ super.key,
+ required this.levels,
+ this.onTapDay,
+ this.firstDay,
+ this.labels = false,
+ this.cellSize,
+ this.weekdays = true,
+ });
final List<int> levels;
final void Function(int index)? onTapDay;
final DateTime? firstDay;
final bool labels;
+ final double? cellSize;
+ final bool weekdays;
Color _color(int level, GymColors gc) => level <= 0 ? gc.heatEmpty : heatLevelColor(gc, level);
@@ -452,12 +462,13 @@ class Heatmap extends StatelessWidget {
final cols = (levels.length / rows).ceil();
final start = firstDay;
final named = labels && start != null;
- final side = named ? 16.0 : 0.0;
+ final side = named && weekdays ? 16.0 : 0.0;
final top = named ? 16.0 : 0.0;
final labelStyle = AppTheme.f(9, weight: FontWeight.w600, color: gc.textTertiary);
+ final yearStyle = AppTheme.f(9, weight: FontWeight.w800, color: gc.textSecondary);
return LayoutBuilder(builder: (context, c) {
- var cell = (c.maxWidth - side - gap * (cols - 1)) / cols;
- if (c.hasBoundedHeight) cell = math.min(cell, (c.maxHeight - top - gap * (rows - 1)) / rows);
+ var cell = cellSize ?? (c.maxWidth - side - gap * (cols - 1)) / cols;
+ if (cellSize == null && c.hasBoundedHeight) cell = math.min(cell, (c.maxHeight - top - gap * (rows - 1)) / rows);
Widget box(int i) {
final level = i < levels.length ? levels[i] : -1;
if (level < 0) return SizedBox(width: cell, height: cell);
@@ -491,12 +502,14 @@ class Heatmap extends StatelessWidget {
final months = <Widget>[];
int? lastMonth;
for (var col = 0; col < cols; col++) {
- final month = shiftDays(start, col * rows).month;
+ final day = shiftDays(start, col * rows);
+ final month = day.month;
if (month != lastMonth && (col > 0 || shiftDays(start, 0).day <= 7)) {
+ final year = cellSize != null && month == 1;
months.add(Positioned(
left: side + col * (cell + gap),
top: 0,
- child: Text(t.monthShort(month), style: labelStyle),
+ child: Text(year ? '${day.year}' : t.monthShort(month), style: year ? yearStyle : labelStyle),
));
}
lastMonth = month;
@@ -506,6 +519,7 @@ class Heatmap extends StatelessWidget {
height: top + rows * cell + (rows - 1) * gap,
child: Stack(clipBehavior: Clip.none, children: [
...months,
+ if (weekdays)
Positioned(
left: 0,
top: top,
@@ -528,6 +542,60 @@ class Heatmap extends StatelessWidget {
}
}
+class HeatmapYear extends StatelessWidget {
+ const HeatmapYear({super.key, required this.levels, required this.firstDay, this.onTapDay, this.weekdays = true});
+ final List<int> levels;
+ final DateTime firstDay;
+ final void Function(int index)? onTapDay;
+ final bool weekdays;
+
+ static const cell = 13.0;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final labelStyle = AppTheme.f(9, weight: FontWeight.w600, color: gc.textTertiary);
+ return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ if (weekdays)
+ Padding(
+ padding: const EdgeInsets.only(top: 16),
+ child: Column(children: [
+ for (var r = 0; r < 7; r++)
+ Container(
+ width: 16,
+ height: cell,
+ margin: EdgeInsets.only(top: r == 0 ? 0 : 4),
+ alignment: Alignment.centerLeft,
+ child: Text(t.weekdayInitial(shiftDays(firstDay, r).weekday), style: labelStyle),
+ ),
+ ]),
+ ),
+ Expanded(
+ child: ShaderMask(
+ shaderCallback: (r) => const LinearGradient(
+ colors: [Color(0x00FFFFFF), Color(0xFFFFFFFF)],
+ stops: [0, 0.08],
+ ).createShader(r),
+ blendMode: BlendMode.dstIn,
+ child: SingleChildScrollView(
+ scrollDirection: Axis.horizontal,
+ reverse: true,
+ padding: const EdgeInsets.only(left: 18),
+ child: Heatmap(
+ levels: levels,
+ firstDay: firstDay,
+ labels: true,
+ weekdays: false,
+ cellSize: cell,
+ onTapDay: onTapDay,
+ ),
+ ),
+ ),
+ ),
+ ]);
+ }
+}
+
class SplitBars extends StatelessWidget {
const SplitBars({super.key, required this.entries});
final List<({String name, int pct})> entries;