Skip to content

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

Follow your progress in photos, or on the muscle map instead

InlitXf61fc64bd1ca
diff --git a/lib/models/progress_shot.dart b/lib/models/progress_shot.dart
new file mode 100644
index 0000000..36189cf
--- /dev/null
+++ b/lib/models/progress_shot.dart
@@ -0,0 +1,63 @@
+const List<String> kPoses = ['front', 'side', 'back'];
+
+class ProgressEntry {
+ const ProgressEntry({
+ required this.id,
+ required this.date,
+ this.shots = const {},
+ this.weightKg,
+ this.note = '',
+ });
+
+ final String id;
+ final DateTime date;
+ final Map<String, String> shots;
+ final double? weightKg;
+ final String note;
+
+ bool get isEmpty => shots.isEmpty;
+
+ List<String> get media => [
+ for (final pose in kPoses)
+ if ((shots[pose] ?? '').isNotEmpty) shots[pose]!,
+ ];
+
+ String? shot(String pose) {
+ final name = shots[pose];
+ return (name == null || name.isEmpty) ? null : name;
+ }
+
+ ProgressEntry copyWith({
+ Map<String, String>? shots,
+ double? weightKg,
+ String? note,
+ bool clearWeight = false,
+ }) =>
+ ProgressEntry(
+ id: id,
+ date: date,
+ shots: shots ?? this.shots,
+ weightKg: clearWeight ? null : (weightKg ?? this.weightKg),
+ note: note ?? this.note,
+ );
+
+ Map<String, dynamic> toJson() => {
+ 'id': id,
+ 'd': date.toIso8601String(),
+ 's': shots,
+ if (weightKg != null) 'w': weightKg,
+ if (note.isNotEmpty) 'n': note,
+ };
+
+ factory ProgressEntry.fromJson(Map<String, dynamic> j) => ProgressEntry(
+ id: (j['id'] ?? '') as String,
+ date: DateTime.tryParse((j['d'] ?? '') as String) ?? DateTime.now(),
+ shots: {
+ for (final e in ((j['s'] as Map?) ?? const {}).entries)
+ if (kPoses.contains(e.key) && e.value is String && (e.value as String).isNotEmpty)
+ e.key as String: e.value as String,
+ },
+ weightKg: (j['w'] as num?)?.toDouble(),
+ note: (j['n'] ?? '') as String,
+ );
+}
diff --git a/lib/screens/compare_screen.dart b/lib/screens/compare_screen.dart
new file mode 100644
index 0000000..ae54e3a
--- /dev/null
+++ b/lib/screens/compare_screen.dart
@@ -0,0 +1,168 @@
+import 'dart:io';
+
+import 'package:flutter/material.dart';
+import 'package:phosphor_flutter/phosphor_flutter.dart';
+
+import '../l10n/l10n.dart';
+import '../models/progress_shot.dart';
+import '../services/media_store.dart';
+import '../state/fit_state.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+import '../widgets/share_cards.dart';
+import '../widgets/svg_icon.dart';
+import '../widgets/ui_kit.dart';
+import 'share_sheet.dart';
+
+class CompareScreen extends StatelessWidget {
+ const CompareScreen({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final pair = fit.comparePair;
+ if (pair == null) return const SizedBox.shrink();
+
+ final poses = fit.posesWithBoth;
+ final pose = poses.contains(fit.comparePose) ? fit.comparePose : (poses.isEmpty ? null : poses.first);
+ final delta = fit.compareWeightDelta;
+ final entries = fit.timelineAsc;
+
+ return SafeArea(
+ bottom: false,
+ child: Column(
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 12, 20, 8),
+ child: Row(
+ children: [
+ RoundBtn(icon: Ic.chevronLeft, onTap: fit.backFromCompare),
+ const SizedBox(width: 12),
+ Expanded(child: ScreenTitle(t.compare, size: 20)),
+ Semantics(
+ button: true,
+ label: t.share,
+ child: GestureDetector(
+ onTap: () => showShareSheet(context, initial: ShareKind.compare),
+ child: Container(
+ width: 36,
+ height: 36,
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ shape: BoxShape.circle,
+ border: Border.all(color: gc.border),
+ ),
+ child: Icon(PhosphorIconsRegular.shareNetwork, size: 16, color: gc.text),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ if (poses.length > 1)
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 6, 20, 0),
+ child: SegToggle([
+ for (final p in poses)
+ SegOption(t.poseName(p), p == pose, () => fit.setComparePose(p)),
+ ]),
+ ),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(20, 16, 20, 0),
+ child: Row(
+ children: [
+ Expanded(child: _shot(gc, pair.from, pose)),
+ const SizedBox(width: 10),
+ Expanded(child: _shot(gc, pair.to, pose)),
+ ],
+ ),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 14, 20, 6),
+ child: Row(
+ children: [
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(t.daysApart(fit.compareDays),
+ style: AppTheme.d(18, weight: FontWeight.w700, color: gc.text)),
+ if (delta != null) ...[
+ const SizedBox(height: 2),
+ Text('${delta > 0 ? '+' : ''}${fmt(delta)} ${fit.units}',
+ style: AppTheme.s(13,
+ weight: FontWeight.w600,
+ color: delta == 0 ? gc.textSecondary : gc.accent)),
+ ],
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ _picker(gc, entries, pair.from.id, fit.setCompareFrom, gc.textSecondary),
+ _picker(gc, entries, pair.to.id, fit.setCompareTo, gc.accent),
+ const SizedBox(height: 16),
+ ],
+ ),
+ );
+ }
+
+ Widget _picker(
+ GymColors gc,
+ List<ProgressEntry> entries,
+ String selectedId,
+ ValueChanged<String> onPick,
+ Color tint,
+ ) =>
+ SizedBox(
+ height: 44,
+ child: ListView(
+ scrollDirection: Axis.horizontal,
+ padding: const EdgeInsets.fromLTRB(20, 4, 20, 4),
+ children: [
+ for (final e in entries)
+ Padding(
+ padding: const EdgeInsets.only(right: 8),
+ child: Pill(
+ label: t.shortDate(e.date),
+ bg: e.id == selectedId ? tint.withValues(alpha: 0.18) : gc.bgRaised,
+ fg: e.id == selectedId ? tint : gc.textTertiary,
+ fontSize: 12,
+ onTap: () => onPick(e.id),
+ ),
+ ),
+ ],
+ ),
+ );
+
+ Widget _shot(GymColors gc, ProgressEntry entry, String? pose) {
+ final name = pose == null ? (entry.media.isEmpty ? null : entry.media.first) : entry.shot(pose);
+ final path = name == null ? null : MediaStore.pathFor(name);
+ return Column(
+ children: [
+ Expanded(
+ child: Container(
+ width: double.infinity,
+ decoration: BoxDecoration(
+ color: gc.bgRaised2,
+ borderRadius: BorderRadius.circular(18),
+ border: Border.all(color: gc.border),
+ ),
+ clipBehavior: Clip.antiAlias,
+ child: path == null
+ ? Icon(PhosphorIconsRegular.imageSquare, size: 22, color: gc.textTertiary)
+ : Image.file(File(path), fit: BoxFit.cover, gaplessPlayback: true,
+ errorBuilder: (_, _, _) =>
+ Icon(PhosphorIconsRegular.imageSquare, size: 22, color: gc.textTertiary)),
+ ),
+ ),
+ const SizedBox(height: 8),
+ Text(t.shortDateYear(entry.date),
+ style: AppTheme.s(11.5, weight: FontWeight.w600, color: gc.textSecondary)),
+ ],
+ );
+ }
+}
diff --git a/lib/screens/timeline_screen.dart b/lib/screens/timeline_screen.dart
new file mode 100644
index 0000000..72d164c
--- /dev/null
+++ b/lib/screens/timeline_screen.dart
@@ -0,0 +1,736 @@
+import 'dart:io';
+import 'dart:math' as math;
+
+import 'package:flutter/material.dart';
+import 'package:image_picker/image_picker.dart';
+import 'package:phosphor_flutter/phosphor_flutter.dart';
+
+import '../l10n/l10n.dart';
+import '../models/progress_shot.dart';
+import '../services/media_store.dart';
+import '../state/fit_state.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+import '../widgets/body_map.dart';
+import '../widgets/note_kit.dart';
+import '../widgets/photo_source_sheet.dart';
+import '../widgets/svg_icon.dart';
+import '../widgets/ui_kit.dart';
+
+class TimelineScreen extends StatefulWidget {
+ const TimelineScreen({super.key});
+
+ @override
+ State<TimelineScreen> createState() => _TimelineScreenState();
+}
+
+class _TimelineScreenState extends State<TimelineScreen> {
+ bool _busy = false;
+
+ Future<void> _shoot(DateTime day, String pose) async {
+ if (_busy) return;
+ final source = await pickPhotoSource(context);
+ if (source == null) return;
+
+ setState(() => _busy = true);
+ try {
+ final shot = await ImagePicker().pickImage(
+ source: source,
+ maxWidth: 1440,
+ maxHeight: 1920,
+ imageQuality: 88,
+ );
+ if (shot == null) return;
+ await fit.attachShot(day, pose, shot.path);
+ } catch (_) {
+ } finally {
+ if (mounted) setState(() => _busy = false);
+ }
+ }
+
+ Future<void> _confirmDelete(ProgressEntry entry) async {
+ final gc = context.gc;
+ final ok = await showDialog<bool>(
+ context: context,
+ builder: (dctx) => AlertDialog(
+ backgroundColor: gc.bgRaised,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
+ title: Text(t.deleteEntryTitle, style: AppTheme.d(18, weight: FontWeight.w700, color: gc.text)),
+ content: Text(t.deleteDayBody, style: AppTheme.s(13, color: gc.textSecondary)),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.of(dctx).pop(false),
+ child: Text(t.cancel, style: AppTheme.s(14, color: gc.textSecondary)),
+ ),
+ TextButton(
+ onPressed: () => Navigator.of(dctx).pop(true),
+ child: Text(t.delete, style: AppTheme.s(14, weight: FontWeight.w700, color: gc.danger)),
+ ),
+ ],
+ ),
+ );
+ if (ok == true) fit.deleteEntry(entry.id);
+ }
+
+ Future<void> _confirmRemove(ProgressEntry entry, String pose) async {
+ final gc = context.gc;
+ final ok = await showDialog<bool>(
+ context: context,
+ builder: (dctx) => AlertDialog(
+ backgroundColor: gc.bgRaised,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
+ title: Text(t.delete, style: AppTheme.d(18, weight: FontWeight.w700, color: gc.text)),
+ content: Text(t.posePhoto(t.poseName(pose).toLowerCase()),
+ style: AppTheme.s(13, color: gc.textSecondary)),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.of(dctx).pop(false),
+ child: Text(t.cancel, style: AppTheme.s(14, color: gc.textSecondary)),
+ ),
+ TextButton(
+ onPressed: () => Navigator.of(dctx).pop(true),
+ child: Text(t.delete, style: AppTheme.s(14, weight: FontWeight.w700, color: gc.danger)),
+ ),
+ ],
+ ),
+ );
+ if (ok == true) fit.removeShot(entry.id, pose);
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final body = fit.bodyTimeline;
+ final entries = fit.timeline;
+ final start = fit.firstEntry;
+ final windows = body ? fit.bodyWindows : const <BodyWindow>[];
+
+ return SafeArea(
+ bottom: false,
+ child: Column(
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 12, 20, 0),
+ child: Row(
+ children: [
+ RoundBtn(icon: Ic.chevronLeft, onTap: fit.backFromTimeline),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ ScreenTitle(t.timeline, size: 20),
+ const SizedBox(height: 2),
+ Text(
+ body
+ ? t.sessionsLogged(fit.totalSessions)
+ : t.photoCount(fit.shotCount),
+ style: AppTheme.s(12.5, color: gc.textSecondary)),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 16),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 20),
+ child: _modeToggle(gc, body),
+ ),
+ Expanded(
+ child: ListView(
+ padding: const EdgeInsets.fromLTRB(20, 18, 20, 20),
+ children: body
+ ? [
+ if (windows.isEmpty)
+ _bodyEmpty(gc)
+ else ...[
+ Text(t.timelineBodyHint,
+ style: AppTheme.s(12.5, color: gc.textTertiary, height: 1.4)),
+ const SizedBox(height: 14),
+ _heatLegend(gc),
+ const SizedBox(height: 22),
+ for (int i = 0; i < windows.length; i++)
+ _bodyRow(gc, windows[i],
+ last: i == windows.length - 1,
+ gap: i == windows.length - 1
+ ? 0
+ : daysBetween(windows[i + 1].to, windows[i].to)),
+ ],
+ ]
+ : [
+ if (entries.isEmpty) _empty(gc) else _heroBand(gc),
+ const SizedBox(height: 20),
+ _intervalPicker(gc),
+ const SizedBox(height: 24),
+ for (int i = 0; i < entries.length; i++)
+ _entryRow(gc, entries[i], start,
+ last: i == entries.length - 1,
+ gap: i == entries.length - 1
+ ? 0
+ : daysBetween(entries[i + 1].date, entries[i].date)),
+ ],
+ ),
+ ),
+ if (!body)
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 4, 20, 20),
+ child: PrimaryButton(
+ label: t.addTodayPhotos,
+ icon: Ic.plus,
+ height: 54,
+ onTap: _busy ? () {} : () => _poseSheet(DateTime.now()),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _modeToggle(GymColors gc, bool body) {
+ Widget tab(String label, IconData icon, bool on, VoidCallback onTap) => Expanded(
+ child: Semantics(
+ button: true,
+ selected: on,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: AnimatedContainer(
+ duration: const Duration(milliseconds: 180),
+ height: 40,
+ decoration: BoxDecoration(
+ color: on ? gc.ember : Colors.transparent,
+ borderRadius: BorderRadius.circular(100),
+ ),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Icon(icon, size: 15, color: on ? gc.onEmber : gc.textSecondary),
+ const SizedBox(width: 7),
+ Text(label,
+ style: AppTheme.s(13,
+ weight: FontWeight.w600, color: on ? gc.onEmber : gc.textSecondary)),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+
+ return Container(
+ padding: const EdgeInsets.all(4),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(100),
+ ),
+ child: Row(
+ children: [
+ tab(t.timelinePhotos, PhosphorIconsRegular.image, !body, () => fit.setBodyTimeline(false)),
+ tab(t.timelineBody, PhosphorIconsRegular.person, body, () => fit.setBodyTimeline(true)),
+ ],
+ ),
+ );
+ }
+
+ Widget _bodyEmpty(GymColors gc) => Container(
+ padding: const EdgeInsets.fromLTRB(22, 26, 22, 26),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(22),
+ ),
+ child: Column(
+ children: [
+ Icon(PhosphorIconsRegular.person, size: 30, color: gc.textTertiary),
+ const SizedBox(height: 16),
+ Text(t.timelineBodyEmpty,
+ textAlign: TextAlign.center,
+ style: AppTheme.s(13, color: gc.textSecondary, height: 1.5)),
+ ],
+ ),
+ );
+
+ Widget _heatLegend(GymColors gc) => Row(
+ children: [
+ Text(t.heatLow, style: AppTheme.s(10.5, color: gc.textTertiary)),
+ const SizedBox(width: 8),
+ for (int i = 0; i <= heatLevels; i++) ...[
+ if (i > 0) const SizedBox(width: 3),
+ Expanded(
+ child: Container(
+ height: 6,
+ decoration: BoxDecoration(
+ color: heatLevelColor(gc, i),
+ borderRadius: BorderRadius.circular(2),
+ ),
+ ),
+ ),
+ ],
+ const SizedBox(width: 8),
+ Text(t.heatHigh, style: AppTheme.s(10.5, color: gc.textTertiary)),
+ ],
+ );
+
+ Widget _bodyRow(GymColors gc, BodyWindow w, {required bool last, required int gap}) {
+ return LayoutBuilder(
+ builder: (context, c) => IntrinsicHeight(
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ _rail(gc, last: last, gap: gap),
+ Expanded(
+ child: Padding(
+ padding: EdgeInsets.only(bottom: last ? 0 : 22),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Text(t.timelineWindow(t.shortDate(w.from), t.shortDate(w.to)),
+ style: AppTheme.d(14, weight: FontWeight.w700, color: gc.text)),
+ const Spacer(),
+ Text(t.sessionCount(w.sessions),
+ style: AppTheme.s(11.5, weight: FontWeight.w600, color: gc.textTertiary)),
+ ],
+ ),
+ const SizedBox(height: 10),
+ SoftCard(
+ radius: 18,
+ padding: const EdgeInsets.symmetric(vertical: 12),
+ child: Center(
+ child: BodyHeatArt(
+ gc: gc,
+ intensity: w.heat,
+ width: math.min(c.maxWidth - 62, 250),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _rail(GymColors gc, {required bool last, required int gap}) {
+ final dash = Color.lerp(gc.border, gc.accent, 0.55)!;
+ return SizedBox(
+ width: 34,
+ child: Column(
+ children: [
+ Container(
+ width: 11,
+ height: 11,
+ margin: const EdgeInsets.only(top: 5),
+ decoration: BoxDecoration(
+ color: gc.accent,
+ shape: BoxShape.circle,
+ border: Border.all(color: gc.accentSoft, width: 3),
+ ),
+ ),
+ if (!last)
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 4),
+ child: Column(
+ children: [
+ Expanded(child: DashedRail(color: dash, thickness: 2.2)),
+ if (gap > 0) ...[
+ const SizedBox(height: 4),
+ Text('${gap}d',
+ style: AppTheme.d(9.5, weight: FontWeight.w700, color: gc.textTertiary)),
+ const SizedBox(height: 4),
+ ],
+ Expanded(child: DashedRail(color: dash, thickness: 2.2)),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _empty(GymColors gc) => Container(
+ padding: const EdgeInsets.fromLTRB(22, 26, 22, 26),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(22),
+ ),
+ child: Column(
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ for (final pose in kPoses) ...[
+ if (pose != kPoses.first) const SizedBox(width: 10),
+ _ghostTile(gc, pose),
+ ],
+ ],
+ ),
+ const SizedBox(height: 20),
+ Text(t.timelineEmptyTitle,
+ textAlign: TextAlign.center,
+ style: AppTheme.d(18, weight: FontWeight.w700, color: gc.text, height: 1.25)),
+ const SizedBox(height: 8),
+ Text(t.timelineHint,
+ textAlign: TextAlign.center,
+ style: AppTheme.s(13, color: gc.textSecondary, height: 1.5)),
+ ],
+ ),
+ );
+
+ Widget _ghostTile(GymColors gc, String pose) => Container(
+ width: 56,
+ height: 72,
+ decoration: BoxDecoration(
+ color: gc.bgRaised2,
+ borderRadius: BorderRadius.circular(12),
+ border: Border.all(color: gc.border),
+ ),
+ child: Center(
+ child: Icon(PhosphorIconsRegular.person, size: 24, color: gc.textTertiary),
+ ),
+ );
+
+ Widget _heroBand(GymColors gc) {
+ final pair = fit.comparePair;
+ if (pair == null) {
+ final only = fit.lastEntry!;
+ return Container(
+ padding: const EdgeInsets.all(18),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(22),
+ ),
+ child: Row(
+ children: [
+ _thumb(gc, only.media.first, 62, 82),
+ const SizedBox(width: 16),
+ Expanded(
+ child: Text(t.compareNeedTwo,
+ style: AppTheme.s(13, color: gc.textSecondary, height: 1.5)),
+ ),
+ ],
+ ),
+ );
+ }
+
+ final pose = fit.posesWithBoth.isEmpty ? null : (fit.posesWithBoth.contains(fit.comparePose)
+ ? fit.comparePose
+ : fit.posesWithBoth.first);
+ final a = pose == null ? pair.from.media.first : pair.from.shot(pose)!;
+ final b = pose == null ? pair.to.media.first : pair.to.shot(pose)!;
+ final delta = fit.compareWeightDelta;
+
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: pose == null ? null : fit.goCompare,
+ child: Container(
+ padding: const EdgeInsets.all(16),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(22),
+ ),
+ child: Column(
+ children: [
+ Row(
+ children: [
+ Expanded(child: _thumb(gc, a, double.infinity, 150)),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 10),
+ child: Icon(PhosphorIconsBold.arrowRight, size: 16, color: gc.accent),
+ ),
+ Expanded(child: _thumb(gc, b, double.infinity, 150)),
+ ],
+ ),
+ const SizedBox(height: 14),
+ Row(
+ children: [
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(t.daysApart(fit.compareDays),
+ style: AppTheme.d(15, weight: FontWeight.w700, color: gc.text)),
+ if (delta != null) ...[
+ const SizedBox(height: 2),
+ Text('${delta > 0 ? '+' : ''}${fmt(delta)} ${fit.units}',
+ style: AppTheme.s(12.5,
+ weight: FontWeight.w600,
+ color: delta == 0 ? gc.textSecondary : gc.accent)),
+ ],
+ ],
+ ),
+ ),
+ if (pose != null)
+ Pill(
+ label: t.compare,
+ bg: gc.ember,
+ fg: gc.onEmber,
+ fontSize: 12,
+ onTap: fit.goCompare,
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _intervalPicker(GymColors gc) {
+ final left = fit.daysUntilPhoto;
+ final due = fit.photoDue;
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Expanded(
+ child: Text(t.photoEvery,
+ style: AppTheme.d(12,
+ weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 2)),
+ ),
+ if (left != null)
+ Text(due ? t.photoDueNow : t.photoNextIn(left),
+ style: AppTheme.s(12,
+ weight: FontWeight.w600, color: due ? gc.accent : gc.textTertiary)),
+ ],
+ ),
+ const SizedBox(height: 10),
+ Container(
+ padding: const EdgeInsets.all(4),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(100),
+ ),
+ child: Row(
+ children: [
+ for (final days in kPhotoIntervals)
+ Expanded(
+ child: Semantics(
+ button: true,
+ selected: fit.photoIntervalDays == days,
+ label: t.photoInterval(days),
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => fit.setPhotoInterval(days),
+ child: AnimatedContainer(
+ duration: const Duration(milliseconds: 180),
+ height: 36,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ color: fit.photoIntervalDays == days ? gc.ember : Colors.transparent,
+ borderRadius: BorderRadius.circular(100),
+ ),
+ child: FittedBox(
+ fit: BoxFit.scaleDown,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 6),
+ child: Text(days <= 0 ? t.photoEveryOff : '$days',
+ maxLines: 1,
+ style: AppTheme.s(13,
+ weight: FontWeight.w600,
+ color: fit.photoIntervalDays == days
+ ? gc.onEmber
+ : gc.textSecondary)),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ );
+ }
+
+ Widget _entryRow(GymColors gc, ProgressEntry entry, ProgressEntry? start,
+ {required bool last, required int gap}) {
+ final dayNo = start == null ? 1 : daysBetween(start.date, entry.date) + 1;
+
+ return IntrinsicHeight(
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ _rail(gc, last: last, gap: gap),
+ Expanded(
+ child: Padding(
+ padding: EdgeInsets.only(bottom: last ? 0 : 22),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Text(t.shortDateYear(entry.date),
+ style: AppTheme.d(14, weight: FontWeight.w700, color: gc.text)),
+ const SizedBox(width: 10),
+ Text(t.dayNumber(dayNo),
+ style: AppTheme.s(11.5, weight: FontWeight.w600, color: gc.textTertiary)),
+ const Spacer(),
+ if (entry.weightKg != null)
+ Text(fit.weightLabel(entry.weightKg!),
+ style: AppTheme.s(12.5, weight: FontWeight.w600, color: gc.textSecondary)),
+ Semantics(
+ button: true,
+ label: t.delete,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => _confirmDelete(entry),
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(10, 4, 0, 4),
+ child: Icon(PhosphorIconsRegular.trash, size: 15, color: gc.textTertiary),
+ ),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 10),
+ Row(
+ children: [
+ for (final pose in kPoses) ...[
+ if (pose != kPoses.first) const SizedBox(width: 10),
+ Expanded(child: _poseTile(gc, entry, pose)),
+ ],
+ ],
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _poseTile(GymColors gc, ProgressEntry entry, String pose) {
+ final name = entry.shot(pose);
+ final path = name == null ? null : MediaStore.pathFor(name);
+
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: name == null
+ ? () => _shoot(entry.date, pose)
+ : () => showNoteMedia(context, entry.media, entry.media.indexOf(name)),
+ onLongPress: name == null ? null : () => _confirmRemove(entry, pose),
+ child: AspectRatio(
+ aspectRatio: 0.78,
+ child: Container(
+ decoration: BoxDecoration(
+ color: gc.bgRaised2,
+ borderRadius: BorderRadius.circular(14),
+ border: Border.all(color: gc.border),
+ ),
+ clipBehavior: Clip.antiAlias,
+ child: path == null
+ ? Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Icon(PhosphorIconsRegular.plus, size: 16, color: gc.textTertiary),
+ const SizedBox(height: 6),
+ Text(t.poseName(pose),
+ style: AppTheme.s(10.5, weight: FontWeight.w600, color: gc.textTertiary)),
+ ],
+ )
+ : Stack(
+ fit: StackFit.expand,
+ children: [
+ Image.file(File(path), fit: BoxFit.cover, gaplessPlayback: true,
+ errorBuilder: (_, _, _) => Icon(PhosphorIconsRegular.imageSquare,
+ size: 20, color: gc.textTertiary)),
+ Positioned(
+ left: 0,
+ right: 0,
+ bottom: 0,
+ child: Container(
+ padding: const EdgeInsets.symmetric(vertical: 4),
+ color: const Color(0x99000000),
+ alignment: Alignment.center,
+ child: Text(t.poseName(pose),
+ style: AppTheme.s(10, weight: FontWeight.w600, color: Colors.white)),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+
+ Widget _thumb(GymColors gc, String name, double w, double h) {
+ final path = MediaStore.pathFor(name);
+ return Container(
+ width: w,
+ height: h,
+ decoration: BoxDecoration(
+ color: gc.bgRaised2,
+ borderRadius: BorderRadius.circular(14),
+ border: Border.all(color: gc.border),
+ ),
+ clipBehavior: Clip.antiAlias,
+ child: path == null
+ ? Icon(PhosphorIconsRegular.imageSquare, size: 18, color: gc.textTertiary)
+ : Image.file(File(path), fit: BoxFit.cover, gaplessPlayback: true,
+ errorBuilder: (_, _, _) =>
+ Icon(PhosphorIconsRegular.imageSquare, size: 18, color: gc.textTertiary)),
+ );
+ }
+
+ Future<void> _poseSheet(DateTime day) async {
+ final gc = context.gc;
+ final pose = await showModalBottomSheet<String>(
+ context: context,
+ backgroundColor: Colors.transparent,
+ builder: (sheet) => Container(
+ padding: const EdgeInsets.fromLTRB(20, 12, 20, 28),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Container(
+ width: 40,
+ height: 4,
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(2)),
+ ),
+ const SizedBox(height: 18),
+ for (final p in kPoses) ...[
+ if (p != kPoses.first) const SizedBox(height: 10),
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => Navigator.of(sheet).pop(p),
+ child: SoftCard(
+ radius: 16,
+ padding: const EdgeInsets.all(16),
+ child: Row(children: [
+ Icon(PhosphorIconsRegular.person, size: 20, color: gc.textSecondary),
+ const SizedBox(width: 14),
+ Expanded(
+ child: Text(t.posePhoto(t.poseName(p).toLowerCase()),
+ style: AppTheme.s(14, weight: FontWeight.w600, color: gc.text)),
+ ),
+ ]),
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ );
+ if (pose != null && mounted) await _shoot(day, pose);
+ }
+}
diff --git a/lib/services/progress_reminder.dart b/lib/services/progress_reminder.dart
new file mode 100644
index 0000000..f178e54
--- /dev/null
+++ b/lib/services/progress_reminder.dart
@@ -0,0 +1,52 @@
+import 'package:flutter/foundation.dart';
+import 'package:flutter_local_notifications/flutter_local_notifications.dart';
+import 'package:timezone/timezone.dart' as tz;
+
+import '../l10n/l10n.dart';
+
+class ProgressReminder {
+ ProgressReminder._();
+ static final ProgressReminder instance = ProgressReminder._();
+
+ static const _id = 1002;
+
+ final _plugin = FlutterLocalNotificationsPlugin();
+ bool enabled = true;
+
+ AndroidNotificationDetails get _android => AndroidNotificationDetails(
+ 'progress_photo',
+ t.notifPhotoChannel,
+ channelDescription: t.notifPhotoChannelWhy,
+ importance: Importance.defaultImportance,
+ priority: Priority.defaultPriority,
+ playSound: true,
+ );
+
+ Future<void> scheduleFor(DateTime day, int intervalDays) async {
+ if (!enabled) return;
+ await cancel();
+ if (intervalDays <= 0) return;
+
+ try {
+ final when = tz.TZDateTime(tz.local, day.year, day.month, day.day, 10);
+ if (!when.isAfter(tz.TZDateTime.now(tz.local))) return;
+ await _plugin.zonedSchedule(
+ id: _id,
+ title: t.notifPhotoTitle,
+ body: t.notifPhotoBody(intervalDays),
+ scheduledDate: when,
+ notificationDetails: NotificationDetails(android: _android),
+ androidScheduleMode: AndroidScheduleMode.inexactAllowWhileIdle,
+ );
+ } catch (e) {
+ debugPrint('No se pudo programar el recordatorio de fotos: $e');
+ }
+ }
+
+ Future<void> cancel() async {
+ if (!enabled) return;
+ try {
+ await _plugin.cancel(id: _id);
+ } catch (_) {}
+ }
+}
diff --git a/lib/state/timeline_state.dart b/lib/state/timeline_state.dart
new file mode 100644
index 0000000..3e07257
--- /dev/null
+++ b/lib/state/timeline_state.dart
@@ -0,0 +1,236 @@
+part of 'fit_state.dart';
+
+const List<int> kPhotoIntervals = [0, 15, 30, 60, 90];
+
+typedef BodyWindow = ({
+ DateTime from,
+ DateTime to,
+ Map<String, double> heat,
+ int sessions,
+ double volume,
+});
+
+mixin TimelineState on FitCore {
+ int photoIntervalDays = 30;
+ bool bodyTimeline = false;
+ String comparePose = 'front';
+ String? compareFromId;
+ String? compareToId;
+
+ List<ProgressEntry> get timeline {
+ final out = shots.where((e) => !e.isEmpty).toList()
+ ..sort((a, b) => b.date.compareTo(a.date));
+ return out;
+ }
+
+ List<ProgressEntry> get timelineAsc => timeline.reversed.toList();
+
+ int get shotCount => shots.fold(0, (n, e) => n + e.shots.length);
+
+ ProgressEntry? get firstEntry {
+ final asc = timelineAsc;
+ return asc.isEmpty ? null : asc.first;
+ }
+
+ ProgressEntry? get lastEntry {
+ final desc = timeline;
+ return desc.isEmpty ? null : desc.first;
+ }
+
+ int get daysTracked {
+ final a = firstEntry, b = lastEntry;
+ if (a == null || b == null) return 0;
+ return daysBetween(a.date, b.date);
+ }
+
+ DateTime? get nextPhotoDue {
+ if (photoIntervalDays <= 0) return null;
+ final last = lastEntry;
+ if (last == null) return null;
+ return DateTime(last.date.year, last.date.month, last.date.day + photoIntervalDays);
+ }
+
+ int? get daysUntilPhoto {
+ final due = nextPhotoDue;
+ if (due == null) return null;
+ return daysBetween(DateTime.now(), due);
+ }
+
+ bool get photoDue {
+ final left = daysUntilPhoto;
+ return left != null && left <= 0;
+ }
+
+ ProgressEntry? entryById(String? id) {
+ if (id == null) return null;
+ for (final e in shots) {
+ if (e.id == id) return e;
+ }
+ return null;
+ }
+
+ ProgressEntry? entryOn(DateTime day) {
+ final key = _dayKey(day);
+ for (final e in shots) {
+ if (_dayKey(e.date) == key) return e;
+ }
+ return null;
+ }
+
+ int _shotSeq = 0;
+
+ ProgressEntry _ensureEntry(DateTime day) {
+ final found = entryOn(day);
+ if (found != null) return found;
+ final entry = ProgressEntry(
+ id: 's${DateTime.now().microsecondsSinceEpoch}-${_shotSeq++}',
+ date: _dayKey(day),
+ weightKg: latestBodyweightKg,
+ );
+ shots.add(entry);
+ return entry;
+ }
+
+ double? get latestBodyweightKg =>
+ bodyweight.isEmpty ? null : (bodyweight.reduce((a, b) => a.date.isAfter(b.date) ? a : b)).kg;
+
+ Future<bool> attachShot(DateTime day, String pose, String srcPath) async {
+ if (!kPoses.contains(pose)) return false;
+ final saved = await MediaStore.importFor('shot', srcPath);
+ if (saved == null) return false;
+ _replaceShot(day, pose, saved);
+ return true;
+ }
+
+ void _replaceShot(DateTime day, String pose, String saved) {
+ final entry = _ensureEntry(day);
+ final old = entry.shot(pose);
+ if (old != null) MediaStore.delete(old);
+ _write(entry.copyWith(shots: {...entry.shots, pose: saved}));
+ _syncPhotoReminder();
+ _persist();
+ notifyListeners();
+ }
+
+ void _write(ProgressEntry updated) {
+ final i = shots.indexWhere((e) => e.id == updated.id);
+ if (i < 0) {
+ shots.add(updated);
+ } else {
+ shots[i] = updated;
+ }
+ }
+
+ void removeShot(String entryId, String pose) {
+ final entry = entryById(entryId);
+ if (entry == null) return;
+ final name = entry.shot(pose);
+ if (name != null) MediaStore.delete(name);
+ final left = {...entry.shots}..remove(pose);
+ if (left.isEmpty) {
+ shots.removeWhere((e) => e.id == entryId);
+ } else {
+ _write(entry.copyWith(shots: left));
+ }
+ _persist();
+ notifyListeners();
+ }
+
+ void deleteEntry(String id) {
+ final entry = entryById(id);
+ if (entry == null) return;
+ for (final name in entry.media) {
+ MediaStore.delete(name);
+ }
+ shots.removeWhere((e) => e.id == id);
+ if (compareFromId == id) compareFromId = null;
+ if (compareToId == id) compareToId = null;
+ _persist();
+ notifyListeners();
+ }
+
+ void setBodyTimeline(bool on) {
+ bodyTimeline = on;
+ _persist();
+ notifyListeners();
+ }
+
+ void setPhotoInterval(int days) {
+ photoIntervalDays = kPhotoIntervals.contains(days) ? days : 30;
+ _syncPhotoReminder();
+ _persist();
+ notifyListeners();
+ }
+
+ void syncPhotoReminder() => _syncPhotoReminder();
+
+ void _syncPhotoReminder() {
+ final due = nextPhotoDue;
+ if (due == null) {
+ ProgressReminder.instance.cancel();
+ return;
+ }
+ ProgressReminder.instance.scheduleFor(due, photoIntervalDays);
+ }
+
+ ({ProgressEntry from, ProgressEntry to})? get comparePair {
+ final asc = timelineAsc;
+ if (asc.length < 2) return null;
+ final from = entryById(compareFromId) ?? asc.first;
+ final to = entryById(compareToId) ?? asc.last;
+ return (from: from, to: to);
+ }
+
+ int get compareDays {
+ final pair = comparePair;
+ if (pair == null) return 0;
+ return daysBetween(pair.from.date, pair.to.date).abs();
+ }
+
+ double? get compareWeightDelta {
+ final pair = comparePair;
+ final a = pair?.from.weightKg, b = pair?.to.weightKg;
+ if (a == null || b == null) return null;
+ return _round1(toDisplayWeight(b) - toDisplayWeight(a));
+ }
+
+ List<String> get posesWithBoth {
+ final pair = comparePair;
+ if (pair == null) return const [];
+ return [
+ for (final p in kPoses)
+ if (pair.from.shot(p) != null && pair.to.shot(p) != null) p,
+ ];
+ }
+
+ void setComparePose(String pose) {
+ comparePose = pose;
+ notifyListeners();
+ }
+
+ void setCompareFrom(String id) {
+ compareFromId = id;
+ notifyListeners();
+ }
+
+ void setCompareTo(String id) {
+ compareToId = id;
+ notifyListeners();
+ }
+
+ void goTimeline() => pushRoute('timeline');
+
+ void backFromTimeline() => popRoute(fallback: 'progress');
+
+ void goCompare() {
+ final pair = comparePair;
+ if (pair == null) return;
+ compareFromId ??= pair.from.id;
+ compareToId ??= pair.to.id;
+ final poses = posesWithBoth;
+ if (poses.isNotEmpty && !poses.contains(comparePose)) comparePose = poses.first;
+ pushRoute('compare');
+ }
+
+ void backFromCompare() => popRoute(fallback: 'timeline');
+}
diff --git a/lib/widgets/photo_source_sheet.dart b/lib/widgets/photo_source_sheet.dart
new file mode 100644
index 0000000..405e226
--- /dev/null
+++ b/lib/widgets/photo_source_sheet.dart
@@ -0,0 +1,62 @@
+import 'package:flutter/material.dart';
+import 'package:image_picker/image_picker.dart';
+import 'package:phosphor_flutter/phosphor_flutter.dart';
+
+import '../l10n/l10n.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+import 'ui_kit.dart';
+
+Future<ImageSource?> pickPhotoSource(BuildContext context) => showModalBottomSheet<ImageSource>(
+ context: context,
+ backgroundColor: Colors.transparent,
+ builder: (_) => const PhotoSourceSheet(),
+ );
+
+class PhotoSourceSheet extends StatelessWidget {
+ const PhotoSourceSheet({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Container(
+ padding: const EdgeInsets.fromLTRB(20, 12, 20, 28),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Container(
+ width: 40,
+ height: 4,
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(2)),
+ ),
+ const SizedBox(height: 18),
+ _option(context, PhosphorIconsRegular.camera, t.takePhoto, ImageSource.camera),
+ const SizedBox(height: 10),
+ _option(context, PhosphorIconsRegular.image, t.chooseGallery, ImageSource.gallery),
+ ],
+ ),
+ );
+ }
+
+ Widget _option(BuildContext context, IconData icon, String label, ImageSource source) {
+ final gc = context.gc;
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => Navigator.of(context).pop(source),
+ child: SoftCard(
+ radius: 16,
+ padding: const EdgeInsets.all(16),
+ child: Row(children: [
+ Icon(icon, size: 20, color: gc.textSecondary),
+ const SizedBox(width: 14),
+ Expanded(child: Text(label, style: AppTheme.s(14, weight: FontWeight.w600, color: gc.text))),
+ ]),
+ ),
+ );
+ }
+}
diff --git a/test/timeline_body_test.dart b/test/timeline_body_test.dart
new file mode 100644
index 0000000..46e3ed9
--- /dev/null
+++ b/test/timeline_body_test.dart
@@ -0,0 +1,112 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:gymmane/l10n/l10n.dart';
+import 'package:gymmane/models/workout.dart';
+import 'package:gymmane/screens/timeline_screen.dart';
+import 'package:gymmane/services/local_store.dart';
+import 'package:gymmane/services/progress_reminder.dart';
+import 'package:gymmane/state/fit_state.dart';
+import 'package:gymmane/theme/app_theme.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+
+Widget _host(Widget Function() screen) => MaterialApp(
+ theme: AppTheme.dark,
+ home: AnimatedBuilder(
+ animation: fit,
+ builder: (_, _) => Scaffold(body: screen()),
+ ),
+ );
+
+LoggedSession _session(int daysAgo, String primary, int sets) => LoggedSession(
+ DateTime.now().subtract(Duration(days: daysAgo)),
+ 1800,
+ [LoggedExercise('x$daysAgo', 'x$daysAgo', primary, List.generate(sets, (_) => LoggedSet(10, 60)))],
+ );
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ setUp(() async {
+ SharedPreferences.setMockInitialValues({});
+ await Store.instance.init();
+ ProgressReminder.instance.enabled = false;
+ setAppLanguage('es');
+ fit.sessions.clear();
+ fit.setPhotoInterval(30);
+ fit.setBodyTimeline(false);
+ });
+
+ tearDown(() {
+ fit.sessions.clear();
+ fit.setBodyTimeline(false);
+ fit.persistNow();
+ });
+
+ test('with no sessions there is no muscle timeline', () {
+ expect(fit.bodyWindows, isEmpty);
+ });
+
+ test('windows walk back from today in interval-sized steps', () {
+ fit.sessions.add(_session(2, 'chest', 4));
+ fit.sessions.add(_session(40, 'quads', 6));
+ fit.setPhotoInterval(30);
+
+ final windows = fit.bodyWindows;
+ expect(windows.length, 2);
+ expect(daysBetween(windows.first.from, windows.first.to), 29);
+ expect(windows.first.sessions, 1);
+ expect(windows.first.heat['chest'], greaterThan(0));
+ expect(windows.last.heat['quads'], greaterThan(0));
+ expect(windows.first.to.isAfter(windows.last.to), true);
+ });
+
+ test('the window follows the interval you picked', () {
+ fit.sessions.add(_session(1, 'back', 4));
+ fit.setPhotoInterval(15);
+ expect(daysBetween(fit.bodyWindows.first.from, fit.bodyWindows.first.to), 14);
+
+ fit.setPhotoInterval(0);
+ expect(fit.bodyWindowDays, 30, reason: 'sin recordatorio la ventana sigue siendo de un mes');
+ });
+
+ test('the muscle map mode survives a save and a reload', () {
+ fit.setBodyTimeline(true);
+ fit.persistNow();
+ fit.bodyTimeline = false;
+ fit.loadFromStore();
+ expect(fit.bodyTimeline, true);
+ });
+
+ testWidgets('every interval button lands on a phone-sized screen', (tester) async {
+ tester.view.physicalSize = const Size(1080, 2400);
+ tester.view.devicePixelRatio = 3;
+ addTearDown(tester.view.reset);
+
+ await tester.pumpWidget(_host(TimelineScreen.new));
+ await tester.pumpAndSettle();
+
+ for (final days in [15, 60, 90, 0]) {
+ final label = days <= 0 ? t.photoEveryOff : '$days';
+ await tester.tap(find.text(label));
+ await tester.pumpAndSettle();
+ expect(fit.photoIntervalDays, days, reason: 'el botón de $label no hizo nada');
+ }
+ fit.persistNow();
+ });
+
+ testWidgets('the muscle map mode drops the photo buttons and draws the body', (tester) async {
+ fit.sessions.add(_session(1, 'chest', 4));
+ await tester.pumpWidget(_host(TimelineScreen.new));
+ await tester.pumpAndSettle();
+
+ expect(find.text(t.addTodayPhotos), findsOneWidget);
+
+ await tester.tap(find.text(t.timelineBody));
+ await tester.pumpAndSettle();
+
+ expect(fit.bodyTimeline, true);
+ expect(find.text(t.addTodayPhotos), findsNothing);
+ expect(find.text(t.timelineBodyHint), findsOneWidget);
+ fit.persistNow();
+ });
+}
diff --git a/test/timeline_test.dart b/test/timeline_test.dart
new file mode 100644
index 0000000..0670f99
--- /dev/null
+++ b/test/timeline_test.dart
@@ -0,0 +1,144 @@
+import 'dart:io';
+import 'dart:typed_data';
+
+import 'package:flutter_test/flutter_test.dart';
+import 'package:gymmane/services/local_store.dart';
+import 'package:gymmane/services/media_store.dart';
+import 'package:gymmane/services/progress_reminder.dart';
+import 'package:gymmane/state/fit_state.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ late Directory tmp;
+ final png = Uint8List.fromList([0x89, 0x50, 0x4E, 0x47, 9, 9, 9, 9]);
+
+ setUp(() async {
+ SharedPreferences.setMockInitialValues({});
+ await Store.instance.init();
+ ProgressReminder.instance.enabled = false;
+ tmp = await Directory.systemTemp.createTemp('gymmane_shots');
+ MediaStore.directory = tmp.path;
+ fit.resetAllData();
+ });
+
+ tearDown(() async {
+ MediaStore.directory = null;
+ try {
+ if (tmp.existsSync()) await tmp.delete(recursive: true);
+ } catch (_) {}
+ });
+
+ Future<String> source(String name) async {
+ final f = File('${tmp.path}/$name');
+ await f.writeAsBytes(png, flush: true);
+ return f.path;
+ }
+
+ test('three poses on one day are one entry, not three', () async {
+ final day = DateTime(2026, 1, 10);
+ for (final pose in ['front', 'side', 'back']) {
+ expect(await fit.attachShot(day, pose, await source('$pose.png')), true);
+ }
+ expect(fit.timeline, hasLength(1));
+ expect(fit.shotCount, 3);
+ expect(fit.timeline.single.shot('back'), isNotNull);
+ });
+
+ test('shooting the same pose again replaces the old file', () async {
+ final day = DateTime(2026, 1, 10);
+ await fit.attachShot(day, 'front', await source('a.png'));
+ final first = fit.timeline.single.shot('front')!;
+ await fit.attachShot(day, 'front', await source('b.png'));
+ final second = fit.timeline.single.shot('front')!;
+
+ expect(second, isNot(first));
+ expect(fit.shotCount, 1);
+ expect(await MediaStore.readBytes(first), isNull, reason: 'la vieja se borra del disco');
+ });
+
+ test('an unknown pose is not accepted', () async {
+ expect(await fit.attachShot(DateTime(2026, 1, 10), 'top', await source('a.png')), false);
+ expect(fit.timeline, isEmpty);
+ });
+
+ test('the timeline reads newest first and knows how long you have been at it', () async {
+ await fit.attachShot(DateTime(2026, 1, 1), 'front', await source('a.png'));
+ await fit.attachShot(DateTime(2026, 3, 2), 'front', await source('b.png'));
+
+ expect(fit.timeline.first.date, DateTime(2026, 3, 2));
+ expect(fit.firstEntry!.date, DateTime(2026, 1, 1));
+ expect(fit.daysTracked, 60);
+ });
+
+ test('dropping the last pose of a day drops the day too', () async {
+ final day = DateTime(2026, 1, 10);
+ await fit.attachShot(day, 'front', await source('a.png'));
+ await fit.attachShot(day, 'back', await source('b.png'));
+
+ final id = fit.timeline.single.id;
+ fit.removeShot(id, 'front');
+ expect(fit.timeline, hasLength(1));
+ fit.removeShot(id, 'back');
+ expect(fit.timeline, isEmpty);
+ });
+
+ test('the reminder date follows the interval and the last photo', () async {
+ expect(fit.nextPhotoDue, isNull, reason: 'sin fotos no hay nada que recordar');
+
+ await fit.attachShot(DateTime(2026, 1, 10), 'front', await source('a.png'));
+ fit.setPhotoInterval(30);
+ expect(fit.nextPhotoDue, DateTime(2026, 2, 9));
+
+ fit.setPhotoInterval(0);
+ expect(fit.nextPhotoDue, isNull);
+ expect(fit.daysUntilPhoto, isNull);
+ });
+
+ test('a rubbish interval falls back to the default', () {
+ fit.setPhotoInterval(7);
+ expect(fit.photoIntervalDays, 30);
+ });
+
+ test('comparing defaults to the first and the last, and only offers shared poses', () async {
+ await fit.attachShot(DateTime(2026, 1, 1), 'front', await source('a.png'));
+ await fit.attachShot(DateTime(2026, 1, 1), 'back', await source('b.png'));
+ await fit.attachShot(DateTime(2026, 4, 1), 'front', await source('c.png'));
+
+ final pair = fit.comparePair!;
+ expect(pair.from.date, DateTime(2026, 1, 1));
+ expect(pair.to.date, DateTime(2026, 4, 1));
+ expect(fit.compareDays, 90);
+ expect(fit.posesWithBoth, ['front'], reason: 'la espalda solo está en un día');
+ });
+
+ test('with a single day there is nothing to compare', () async {
+ await fit.attachShot(DateTime(2026, 1, 1), 'front', await source('a.png'));
+ expect(fit.comparePair, isNull);
+ });
+
+ test('the day keeps the bodyweight you had, and the delta uses your units', () async {
+ fit.setUnits('kg');
+ fit.addBodyweight(80);
+ await fit.attachShot(DateTime(2026, 1, 1), 'front', await source('a.png'));
+ fit.addBodyweight(76);
+ await fit.attachShot(DateTime(2026, 4, 1), 'front', await source('b.png'));
+
+ expect(fit.compareWeightDelta, closeTo(-4, 0.01));
+ });
+
+ test('photos survive a save and a reload, and reset wipes them', () async {
+ await fit.attachShot(DateTime(2026, 1, 1), 'front', await source('a.png'));
+ fit.setPhotoInterval(60);
+ fit.persistNow();
+
+ fit.shots.clear();
+ fit.loadFromStore();
+ expect(fit.timeline, hasLength(1));
+ expect(fit.photoIntervalDays, 60);
+
+ fit.resetAllData();
+ expect(fit.shots, isEmpty);
+ });
+}