Skip to content

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

Keep a training journal on a calendar

InlitX4d380220e959
diff --git a/lib/models/note.dart b/lib/models/note.dart
new file mode 100644
index 0000000..0d06916
--- /dev/null
+++ b/lib/models/note.dart
@@ -0,0 +1,70 @@
+enum NoteKind { note, plan, done, pain }
+
+class GymNote {
+ const GymNote({
+ required this.id,
+ required this.exerciseId,
+ required this.date,
+ required this.kind,
+ required this.text,
+ this.media = const [],
+ required this.createdAt,
+ });
+
+ final String id;
+ final String exerciseId;
+ final DateTime date;
+ final NoteKind kind;
+ final String text;
+ final List<String> media;
+ final DateTime createdAt;
+
+ bool get isGeneral => exerciseId.isEmpty;
+
+ String get title => text.trim().split('\n').first;
+
+ String get body {
+ final lines = text.trim().split('\n');
+ return lines.length > 1 ? lines.sublist(1).join('\n').trim() : '';
+ }
+
+ GymNote copyWith({
+ String? exerciseId,
+ DateTime? date,
+ NoteKind? kind,
+ String? text,
+ List<String>? media,
+ }) =>
+ GymNote(
+ id: id,
+ exerciseId: exerciseId ?? this.exerciseId,
+ date: date ?? this.date,
+ kind: kind ?? this.kind,
+ text: text ?? this.text,
+ media: media ?? this.media,
+ createdAt: createdAt,
+ );
+
+ Map<String, dynamic> toJson() => {
+ 'id': id,
+ 'x': exerciseId,
+ 'd': date.toIso8601String(),
+ 'k': kind.index,
+ 't': text,
+ if (media.isNotEmpty) 'm': media,
+ 'c': createdAt.toIso8601String(),
+ };
+
+ factory GymNote.fromJson(Map<String, dynamic> j) {
+ final created = DateTime.tryParse((j['c'] ?? '') as String) ?? DateTime.now();
+ return GymNote(
+ id: (j['id'] ?? '') as String,
+ exerciseId: (j['x'] ?? '') as String,
+ date: DateTime.tryParse((j['d'] ?? '') as String) ?? created,
+ kind: NoteKind.values[((j['k'] ?? 0) as num).toInt().clamp(0, NoteKind.values.length - 1)],
+ text: (j['t'] ?? '') as String,
+ media: ((j['m'] as List?) ?? const []).cast<String>(),
+ createdAt: created,
+ );
+ }
+}
diff --git a/lib/screens/note_edit_screen.dart b/lib/screens/note_edit_screen.dart
new file mode 100644
index 0000000..9105495
--- /dev/null
+++ b/lib/screens/note_edit_screen.dart
@@ -0,0 +1,428 @@
+import 'package:file_picker/file_picker.dart';
+import 'package:flutter/material.dart';
+import 'package:phosphor_flutter/phosphor_flutter.dart';
+
+import '../l10n/l10n.dart';
+import '../models/exercise.dart';
+import '../models/note.dart';
+import '../services/media_store.dart';
+import '../state/fit_state.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+import '../widgets/note_kit.dart';
+import '../widgets/svg_icon.dart';
+import '../widgets/ui_kit.dart';
+
+const int _kNoteMaxLength = 1000;
+
+class NoteEditScreen extends StatefulWidget {
+ const NoteEditScreen({super.key});
+
+ @override
+ State<NoteEditScreen> createState() => _NoteEditScreenState();
+}
+
+class _NoteEditScreenState extends State<NoteEditScreen> {
+ late final GymNote? _note = fit.editingNote;
+ late final TextEditingController _text = TextEditingController(text: _note?.text ?? '');
+ late NoteKind _kind = _note?.kind ?? fit.noteDraftKind;
+ late DateTime _date = _note?.date ?? fit.noteDraftDate;
+ late String _exerciseId = _note?.exerciseId ?? fit.noteDraftExercise;
+ late final List<String> _media = [...?_note?.media];
+ final List<String> _added = [];
+ bool _saved = false;
+
+ bool get _canSave => _text.text.trim().isNotEmpty;
+
+ @override
+ void dispose() {
+ for (final name in _added) {
+ if (!_saved || !_media.contains(name)) MediaStore.delete(name);
+ }
+ _text.dispose();
+ super.dispose();
+ }
+
+ void _save() {
+ if (!_canSave) return;
+ _saved = true;
+ fit.saveNote(
+ id: _note?.id,
+ exerciseId: _exerciseId,
+ date: _date,
+ kind: _kind,
+ text: _text.text,
+ media: _media,
+ );
+ fit.closeNoteEditor();
+ }
+
+ Future<void> _pickDate() async {
+ final picked = await showDatePicker(
+ context: context,
+ initialDate: _date,
+ firstDate: DateTime(2015),
+ lastDate: DateTime.now().add(const Duration(days: 365)),
+ );
+ if (picked != null) setState(() => _date = picked);
+ }
+
+ Future<void> _addMedia() async {
+ try {
+ final res = await FilePicker.platform.pickFiles(type: FileType.media, allowMultiple: true);
+ for (final f in res?.files ?? const <PlatformFile>[]) {
+ final path = f.path;
+ if (path == null) continue;
+ final saved = await fit.importNoteMedia(path);
+ if (saved == null) continue;
+ _added.add(saved);
+ if (mounted) setState(() => _media.add(saved));
+ }
+ } catch (_) {}
+ }
+
+ Future<void> _confirmDelete() async {
+ final note = _note;
+ if (note == null) return;
+ 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.deleteNoteTitle, style: AppTheme.d(18, weight: FontWeight.w700, color: gc.text)),
+ content: Text(t.deleteNoteBody, 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) return;
+ fit.deleteNote(note.id);
+ fit.closeNoteEditor();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final exercise = _exerciseId.isEmpty ? null : fit.exerciseById(_exerciseId);
+
+ return SafeArea(
+ bottom: false,
+ child: GestureDetector(
+ onTap: () => FocusScope.of(context).unfocus(),
+ excludeFromSemantics: true,
+ child: Column(
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 12, 20, 8),
+ child: Row(
+ children: [
+ RoundBtn(icon: Ic.chevronLeft, onTap: fit.closeNoteEditor),
+ const SizedBox(width: 12),
+ Expanded(child: ScreenTitle(_note == null ? t.newNote : t.editNote, size: 20)),
+ if (_note != null)
+ Semantics(
+ button: true,
+ label: t.delete,
+ child: GestureDetector(
+ onTap: _confirmDelete,
+ child: Container(
+ width: 36,
+ height: 36,
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ shape: BoxShape.circle,
+ border: Border.all(color: gc.border),
+ ),
+ child: Icon(PhosphorIconsRegular.trash, size: 16, color: gc.danger),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ Expanded(
+ child: ListView(
+ padding: const EdgeInsets.fromLTRB(20, 8, 20, 24),
+ children: [
+ _label(gc, t.noteKindLabel),
+ NoteKindPicker(selected: _kind, onChanged: (k) => setState(() => _kind = k)),
+ const SizedBox(height: 22),
+ _label(gc, t.noteTextLabel),
+ Container(
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(16),
+ ),
+ padding: const EdgeInsets.fromLTRB(16, 6, 16, 6),
+ child: TextField(
+ controller: _text,
+ autofocus: _note == null,
+ minLines: 4,
+ maxLines: 10,
+ maxLength: _kNoteMaxLength,
+ textCapitalization: TextCapitalization.sentences,
+ onChanged: (_) => setState(() {}),
+ cursorColor: gc.accent,
+ style: AppTheme.s(14.5, color: gc.text, height: 1.45),
+ decoration: InputDecoration(
+ border: InputBorder.none,
+ hintText: t.notePlaceholder,
+ hintStyle: AppTheme.s(14.5, color: gc.textTertiary),
+ counterStyle: AppTheme.s(11, color: gc.textTertiary),
+ ),
+ ),
+ ),
+ const SizedBox(height: 22),
+ _label(gc, t.noteDateLabel),
+ _row(
+ gc,
+ icon: PhosphorIconsRegular.calendarBlank,
+ value: t.shortDateYear(_date),
+ onTap: _pickDate,
+ ),
+ const SizedBox(height: 14),
+ _label(gc, t.noteExerciseLabel),
+ _row(
+ gc,
+ icon: PhosphorIconsRegular.barbell,
+ value: exercise == null ? t.noteGeneral : exerciseName(exercise),
+ muted: exercise == null,
+ trailing: exercise == null
+ ? null
+ : Semantics(
+ button: true,
+ label: t.noteGeneral,
+ child: GestureDetector(
+ onTap: () => setState(() => _exerciseId = ''),
+ child: Padding(
+ padding: const EdgeInsets.all(6),
+ child: Icon(PhosphorIconsBold.x, size: 14, color: gc.textTertiary),
+ ),
+ ),
+ ),
+ onTap: _pickExercise,
+ ),
+ const SizedBox(height: 22),
+ _label(gc, t.noteMediaLabel),
+ _mediaGrid(gc),
+ const SizedBox(height: 28),
+ PrimaryButton(
+ label: t.save,
+ onTap: _save,
+ bg: _canSave ? gc.ember : gc.mutedFill,
+ fg: _canSave ? gc.onEmber : gc.textTertiary,
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _label(GymColors gc, String text) => Padding(
+ padding: const EdgeInsets.only(bottom: 10),
+ child: Text(text,
+ style: AppTheme.d(12, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 2)),
+ );
+
+ Widget _row(
+ GymColors gc, {
+ required IconData icon,
+ required String value,
+ required VoidCallback onTap,
+ Widget? trailing,
+ bool muted = false,
+ }) =>
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: SoftCard(
+ radius: 14,
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
+ child: Row(
+ children: [
+ Icon(icon, size: 17, color: gc.textSecondary),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Text(value,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.s(14,
+ weight: FontWeight.w500, color: muted ? gc.textTertiary : gc.text)),
+ ),
+ trailing ??
+ Icon(PhosphorIconsRegular.caretRight, size: 14, color: gc.textTertiary),
+ ],
+ ),
+ ),
+ );
+
+ Widget _mediaGrid(GymColors gc) {
+ return Wrap(
+ spacing: 10,
+ runSpacing: 10,
+ children: [
+ for (int i = 0; i < _media.length; i++)
+ GestureDetector(
+ onTap: () => showNoteMedia(context, _media, i),
+ child: NoteThumb(
+ name: _media[i],
+ size: 74,
+ onRemove: () => setState(() => _media.removeAt(i)),
+ ),
+ ),
+ Semantics(
+ button: true,
+ label: t.noteAttach,
+ child: GestureDetector(
+ onTap: _addMedia,
+ child: Container(
+ width: 74,
+ height: 74,
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ borderRadius: BorderRadius.circular(12),
+ border: Border.all(color: gc.border),
+ ),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Icon(PhosphorIconsRegular.images, size: 20, color: gc.textSecondary),
+ const SizedBox(height: 5),
+ Text(t.noteAttach, style: AppTheme.s(10.5, color: gc.textTertiary)),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+
+ Future<void> _pickExercise() async {
+ final picked = await showModalBottomSheet<String>(
+ context: context,
+ isScrollControlled: true,
+ backgroundColor: Colors.transparent,
+ builder: (_) => const _ExercisePickerSheet(),
+ );
+ if (picked != null && mounted) setState(() => _exerciseId = picked);
+ }
+}
+
+class _ExercisePickerSheet extends StatefulWidget {
+ const _ExercisePickerSheet();
+
+ @override
+ State<_ExercisePickerSheet> createState() => _ExercisePickerSheetState();
+}
+
+class _ExercisePickerSheetState extends State<_ExercisePickerSheet> {
+ final TextEditingController _q = TextEditingController();
+
+ @override
+ void dispose() {
+ _q.dispose();
+ super.dispose();
+ }
+
+ List<Exercise> get _results {
+ final q = _q.text.trim().toLowerCase();
+ final all = fit.allExercises;
+ if (q.isEmpty) return all.take(40).toList();
+ return all
+ .where((e) =>
+ e.name.toLowerCase().contains(q) || exerciseName(e).toLowerCase().contains(q))
+ .take(60)
+ .toList();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final results = _results;
+
+ return Padding(
+ padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
+ child: Container(
+ height: MediaQuery.of(context).size.height * 0.72,
+ decoration: BoxDecoration(
+ color: gc.bg,
+ border: Border.all(color: gc.border),
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(26)),
+ ),
+ clipBehavior: Clip.antiAlias,
+ child: Column(
+ children: [
+ Container(
+ width: 40,
+ height: 4,
+ margin: const EdgeInsets.symmetric(vertical: 12),
+ decoration: BoxDecoration(color: gc.border, borderRadius: BorderRadius.circular(2)),
+ ),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 0, 20, 12),
+ child: TextField(
+ controller: _q,
+ autofocus: true,
+ onChanged: (_) => setState(() {}),
+ cursorColor: gc.accent,
+ style: AppTheme.s(14, color: gc.text),
+ decoration: InputDecoration(
+ hintText: t.searchAllExercises,
+ hintStyle: AppTheme.s(14, color: gc.textTertiary),
+ filled: true,
+ fillColor: gc.bgRaised,
+ prefixIcon: Icon(PhosphorIconsRegular.magnifyingGlass, size: 17, color: gc.textTertiary),
+ contentPadding: const EdgeInsets.symmetric(vertical: 12),
+ enabledBorder: OutlineInputBorder(
+ borderRadius: BorderRadius.circular(14), borderSide: BorderSide(color: gc.border)),
+ focusedBorder: OutlineInputBorder(
+ borderRadius: BorderRadius.circular(14), borderSide: BorderSide(color: gc.accent)),
+ ),
+ ),
+ ),
+ Expanded(
+ child: ListView.builder(
+ padding: const EdgeInsets.fromLTRB(20, 0, 20, 24),
+ itemCount: results.length + 1,
+ itemBuilder: (context, i) {
+ if (i == 0) {
+ return _tile(gc, t.noteGeneral, muted: true, onTap: () => Navigator.of(context).pop(''));
+ }
+ final ex = results[i - 1];
+ return _tile(gc, exerciseName(ex), onTap: () => Navigator.of(context).pop(ex.id));
+ },
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _tile(GymColors gc, String label, {required VoidCallback onTap, bool muted = false}) =>
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: Container(
+ padding: const EdgeInsets.symmetric(vertical: 14),
+ decoration: BoxDecoration(border: Border(bottom: BorderSide(color: gc.border))),
+ child: Text(label,
+ style: AppTheme.s(14,
+ weight: FontWeight.w500, color: muted ? gc.textTertiary : gc.text)),
+ ),
+ );
+}
diff --git a/lib/screens/notes_screen.dart b/lib/screens/notes_screen.dart
new file mode 100644
index 0000000..142cd58
--- /dev/null
+++ b/lib/screens/notes_screen.dart
@@ -0,0 +1,259 @@
+import 'package:flutter/material.dart';
+import 'package:phosphor_flutter/phosphor_flutter.dart';
+
+import '../l10n/l10n.dart';
+import '../models/exercise.dart';
+import '../models/note.dart';
+import '../state/fit_state.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+import '../widgets/note_kit.dart';
+import '../widgets/svg_icon.dart';
+import '../widgets/ui_kit.dart';
+
+class NotesScreen extends StatelessWidget {
+ const NotesScreen({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final scoped = fit.noteScope.isEmpty ? null : fit.exerciseById(fit.noteScope);
+ final all = fit.notesAllView;
+
+ 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.backFromNotes),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ ScreenTitle(
+ scoped == null ? t.journal : exerciseName(scoped).toUpperCase(),
+ size: 20,
+ ),
+ const SizedBox(height: 2),
+ Text(
+ all
+ ? t.noteCount(fit.notesInScope.length)
+ : t.noteMonthCount(fit.notesInMonth),
+ style: AppTheme.s(12.5, color: gc.textSecondary)),
+ ],
+ ),
+ ),
+ _action(
+ gc,
+ icon: PhosphorIconsBold.plus,
+ label: t.addNote,
+ filled: true,
+ onTap: () => fit.openNoteEditor(
+ exerciseId: fit.noteScope,
+ date: all ? DateTime.now() : fit.noteDay,
+ ),
+ ),
+ const SizedBox(width: 8),
+ _action(
+ gc,
+ icon: all ? PhosphorIconsRegular.calendarBlank : PhosphorIconsRegular.listBullets,
+ label: all ? t.noteCalendar : t.noteAllNotes,
+ onTap: () => fit.setNotesAllView(!all),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 16),
+ Expanded(
+ child: all
+ ? _allNotes(gc, scoped == null)
+ : _calendar(context, gc, scoped == null)),
+ ],
+ ),
+ );
+ }
+
+ Widget _action(
+ GymColors gc, {
+ required IconData icon,
+ required String label,
+ required VoidCallback onTap,
+ bool filled = false,
+ }) =>
+ Semantics(
+ button: true,
+ label: label,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: Container(
+ width: 38,
+ height: 38,
+ decoration: BoxDecoration(
+ color: filled ? gc.ember : gc.bgRaised,
+ shape: BoxShape.circle,
+ border: Border.all(color: filled ? gc.ember : gc.border),
+ ),
+ child: Icon(icon, size: 16, color: filled ? gc.onEmber : gc.text),
+ ),
+ ),
+ );
+
+ Widget _calendar(BuildContext context, GymColors gc, bool showExercise) {
+ final day = fit.noteDay;
+ final notes = fit.notesOn(day);
+
+ return ListView(
+ padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
+ children: [
+ SoftCard(
+ radius: 22,
+ padding: const EdgeInsets.fromLTRB(12, 14, 12, 10),
+ child: NoteCalendar(
+ month: fit.noteMonth,
+ selected: day,
+ kindsOn: fit.noteKindsOn,
+ onPick: fit.selectNoteDay,
+ onHold: (day) {
+ fit.selectNoteDay(day);
+ showNoteDaySheet(context, day);
+ },
+ onMonth: fit.showNoteMonth,
+ ),
+ ),
+ const SizedBox(height: 22),
+ Row(
+ children: [
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(noteDayLabel(day).toUpperCase(),
+ style: AppTheme.d(12,
+ weight: FontWeight.w700, color: gc.text, letterSpacing: 2)),
+ const SizedBox(height: 3),
+ Text(t.fullDate(day), style: AppTheme.s(12, color: gc.textTertiary)),
+ ],
+ ),
+ ),
+ Pill(
+ label: t.noteAddOnDay,
+ bg: gc.bgRaised,
+ fg: gc.text,
+ fontSize: 12,
+ onTap: () => fit.openNoteEditor(exerciseId: fit.noteScope, date: day),
+ ),
+ ],
+ ),
+ const SizedBox(height: 14),
+ if (notes.isEmpty)
+ Container(
+ padding: const EdgeInsets.symmetric(vertical: 26, horizontal: 20),
+ decoration: BoxDecoration(
+ color: gc.bgRaised.withValues(alpha: 0.5),
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(18),
+ ),
+ child: Row(
+ children: [
+ Icon(PhosphorIconsRegular.notebook, size: 20, color: gc.textTertiary),
+ const SizedBox(width: 14),
+ Expanded(
+ child: Text(t.noteNoneOnDay,
+ style: AppTheme.s(13, color: gc.textSecondary, height: 1.4)),
+ ),
+ ],
+ ),
+ )
+ else
+ for (final n in notes) NoteCard(note: n, showExercise: showExercise, showDate: false),
+ ],
+ );
+ }
+
+ Widget _allNotes(GymColors gc, bool showExercise) {
+ final visible = fit.notesFiltered;
+
+ return Column(
+ children: [
+ if (fit.notesInScope.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 20),
+ child: NoteFilterBar(
+ selected: fit.noteFilter,
+ counts: fit.noteKindCounts,
+ onPick: fit.setNoteFilter,
+ ),
+ ),
+ Expanded(
+ child: visible.isEmpty
+ ? _empty(gc)
+ : ListView(
+ padding: const EdgeInsets.fromLTRB(20, 14, 20, 20),
+ children: _grouped(gc, visible, showExercise: showExercise),
+ ),
+ ),
+ ],
+ );
+ }
+
+ List<Widget> _grouped(GymColors gc, List<GymNote> notes, {required bool showExercise}) {
+ final out = <Widget>[];
+ DateTime? day;
+ for (final n in notes) {
+ final d = DateTime(n.date.year, n.date.month, n.date.day);
+ if (day == null || d != day) {
+ day = d;
+ out.add(Padding(
+ padding: EdgeInsets.only(top: out.isEmpty ? 0 : 14, bottom: 12),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(noteDayLabel(d).toUpperCase(),
+ style: AppTheme.d(12.5,
+ weight: FontWeight.w700, color: gc.text, letterSpacing: 2)),
+ const SizedBox(height: 3),
+ Text(t.fullDate(d), style: AppTheme.s(11.5, color: gc.textTertiary)),
+ ],
+ ),
+ const SizedBox(width: 12),
+ Expanded(child: Padding(
+ padding: const EdgeInsets.only(bottom: 6),
+ child: Container(height: 1, color: gc.border),
+ )),
+ ],
+ ),
+ ));
+ }
+ out.add(NoteCard(note: n, showExercise: showExercise, showDate: false));
+ }
+ return out;
+ }
+
+ Widget _empty(GymColors gc) => Center(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 44),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(PhosphorIconsRegular.notebook, size: 38, color: gc.textTertiary),
+ const SizedBox(height: 16),
+ Text(t.noteEmptyTitle,
+ textAlign: TextAlign.center,
+ style: AppTheme.d(17, weight: FontWeight.w600, color: gc.text)),
+ const SizedBox(height: 8),
+ Text(t.noteEmptyBody,
+ textAlign: TextAlign.center,
+ style: AppTheme.s(13, color: gc.textSecondary, height: 1.5)),
+ ],
+ ),
+ ),
+ );
+}
diff --git a/lib/state/notes_state.dart b/lib/state/notes_state.dart
new file mode 100644
index 0000000..bd8f694
--- /dev/null
+++ b/lib/state/notes_state.dart
@@ -0,0 +1,186 @@
+part of 'fit_state.dart';
+
+mixin NotesState on FitCore, LibraryState {
+ NoteKind? noteFilter;
+ String noteScope = '';
+ String? editingNoteId;
+ String noteDraftExercise = '';
+ DateTime noteDraftDate = DateTime.now();
+ NoteKind noteDraftKind = NoteKind.note;
+ bool notesAllView = false;
+ DateTime noteMonth = DateTime(DateTime.now().year, DateTime.now().month);
+ DateTime noteDay = _dayKey(DateTime.now());
+ int _noteSeq = 0;
+
+ int _noteRank(GymNote n) => n.date.millisecondsSinceEpoch;
+
+ List<GymNote> get notesSorted {
+ final list = [...notes];
+ list.sort((a, b) {
+ final byDay = _noteRank(b).compareTo(_noteRank(a));
+ return byDay != 0 ? byDay : b.createdAt.compareTo(a.createdAt);
+ });
+ return list;
+ }
+
+ List<GymNote> notesFor(String exerciseId) =>
+ notesSorted.where((n) => n.exerciseId == exerciseId).toList();
+
+ GymNote? noteById(String? id) {
+ if (id == null) return null;
+ for (final n in notes) {
+ if (n.id == id) return n;
+ }
+ return null;
+ }
+
+ GymNote? get editingNote => noteById(editingNoteId);
+
+ List<GymNote> get notesInScope =>
+ noteScope.isEmpty ? notesSorted : notesFor(noteScope);
+
+ List<GymNote> get notesFiltered {
+ final scoped = notesInScope;
+ return noteFilter == null ? scoped : scoped.where((n) => n.kind == noteFilter).toList();
+ }
+
+ List<GymNote> notesOn(DateTime day) {
+ final key = _dayKey(day);
+ return notesInScope.where((n) => _dayKey(n.date) == key).toList();
+ }
+
+ List<NoteKind> noteKindsOn(DateTime day) {
+ final seen = <NoteKind>[];
+ for (final n in notesOn(day)) {
+ if (!seen.contains(n.kind)) seen.add(n.kind);
+ }
+ seen.sort((a, b) => a.index.compareTo(b.index));
+ return seen;
+ }
+
+ int get notesInMonth => notesInScope
+ .where((n) => n.date.year == noteMonth.year && n.date.month == noteMonth.month)
+ .length;
+
+ void showNoteMonth(int delta) {
+ noteMonth = DateTime(noteMonth.year, noteMonth.month + delta);
+ notifyListeners();
+ }
+
+ void selectNoteDay(DateTime day) {
+ noteDay = _dayKey(day);
+ noteMonth = DateTime(noteDay.year, noteDay.month);
+ notifyListeners();
+ }
+
+ void setNotesAllView(bool all) {
+ notesAllView = all;
+ notifyListeners();
+ }
+
+ Map<NoteKind, int> get noteKindCounts {
+ final out = {for (final k in NoteKind.values) k: 0};
+ for (final n in notesInScope) {
+ out[n.kind] = out[n.kind]! + 1;
+ }
+ return out;
+ }
+
+ String noteExerciseName(GymNote n) {
+ if (n.isGeneral) return '';
+ final ex = exerciseById(n.exerciseId);
+ return ex == null ? '' : exerciseName(ex);
+ }
+
+ void setNoteFilter(NoteKind? k) {
+ noteFilter = noteFilter == k ? null : k;
+ notifyListeners();
+ }
+
+ Future<String?> importNoteMedia(String srcPath) => MediaStore.importFor('note', srcPath);
+
+ void saveNote({
+ String? id,
+ required String exerciseId,
+ required DateTime date,
+ required NoteKind kind,
+ required String text,
+ List<String> media = const [],
+ }) {
+ final body = text.trim();
+ if (body.isEmpty) return;
+ final day = _dayKey(date);
+ final index = id == null ? -1 : notes.indexWhere((n) => n.id == id);
+
+ if (index < 0) {
+ notes.add(GymNote(
+ id: 'n${DateTime.now().microsecondsSinceEpoch}-${_noteSeq++}',
+ exerciseId: exerciseId,
+ date: day,
+ kind: kind,
+ text: body,
+ media: [...media],
+ createdAt: DateTime.now(),
+ ));
+ } else {
+ final old = notes[index];
+ for (final m in old.media) {
+ if (!media.contains(m)) MediaStore.delete(m);
+ }
+ notes[index] = old.copyWith(
+ exerciseId: exerciseId,
+ date: day,
+ kind: kind,
+ text: body,
+ media: [...media],
+ );
+ }
+ noteDay = day;
+ noteMonth = DateTime(day.year, day.month);
+ _persist();
+ notifyListeners();
+ }
+
+ void deleteNote(String id) {
+ final index = notes.indexWhere((n) => n.id == id);
+ if (index < 0) return;
+ for (final m in notes[index].media) {
+ MediaStore.delete(m);
+ }
+ notes.removeAt(index);
+ _persist();
+ notifyListeners();
+ }
+
+ void goNotes({String exerciseId = '', bool all = false}) {
+ noteScope = exerciseId;
+ noteFilter = null;
+ notesAllView = all;
+ noteDay = _dayKey(DateTime.now());
+ noteMonth = DateTime(noteDay.year, noteDay.month);
+ pushRoute('notes');
+ }
+
+ void backFromNotes() {
+ if (notesAllView) {
+ notesAllView = false;
+ notifyListeners();
+ return;
+ }
+ popRoute();
+ }
+
+ void openNoteEditor({String? id, String exerciseId = '', DateTime? date, NoteKind? kind}) {
+ final existing = noteById(id);
+ editingNoteId = existing?.id;
+ noteDraftExercise = existing?.exerciseId ?? exerciseId;
+ noteDraftDate = existing?.date ?? _dayKey(date ?? DateTime.now());
+ noteDraftKind = existing?.kind ?? kind ?? NoteKind.note;
+ pushRoute('note-edit');
+ }
+
+ void closeNoteEditor() {
+ editingNoteId = null;
+ popRoute();
+ }
+}
diff --git a/lib/widgets/note_kit.dart b/lib/widgets/note_kit.dart
new file mode 100644
index 0000000..99fb14c
--- /dev/null
+++ b/lib/widgets/note_kit.dart
@@ -0,0 +1,786 @@
+import 'dart:io';
+
+import 'package:flutter/material.dart';
+import 'package:phosphor_flutter/phosphor_flutter.dart';
+import 'package:video_player/video_player.dart';
+
+import '../l10n/l10n.dart';
+import '../models/note.dart';
+import '../services/media_store.dart';
+import '../state/fit_state.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+
+Color noteKindColor(GymColors gc, NoteKind k) => switch (k) {
+ NoteKind.note => gc.info,
+ NoteKind.plan => gc.warn,
+ NoteKind.done => gc.sage,
+ NoteKind.pain => gc.danger,
+ };
+
+String noteKindLabel(NoteKind k) => switch (k) {
+ NoteKind.note => t.noteKindNote,
+ NoteKind.plan => t.noteKindPlan,
+ NoteKind.done => t.noteKindDone,
+ NoteKind.pain => t.noteKindPain,
+ };
+
+IconData noteKindIcon(NoteKind k) => switch (k) {
+ NoteKind.note => PhosphorIconsRegular.notePencil,
+ NoteKind.plan => PhosphorIconsRegular.crosshair,
+ NoteKind.done => PhosphorIconsRegular.checkCircle,
+ NoteKind.pain => PhosphorIconsRegular.warning,
+ };
+
+String noteDayLabel(DateTime d) {
+ final now = DateTime.now();
+ final diff = daysBetween(d, now);
+ if (diff == 0) return t.noteToday;
+ if (diff == 1) return t.noteYesterday;
+ return now.year == d.year ? t.shortDate(d) : t.shortDateYear(d);
+}
+
+class NoteCalendar extends StatelessWidget {
+ const NoteCalendar({
+ super.key,
+ required this.month,
+ required this.selected,
+ required this.kindsOn,
+ required this.onPick,
+ required this.onHold,
+ required this.onMonth,
+ });
+
+ final DateTime month;
+ final DateTime selected;
+ final List<NoteKind> Function(DateTime day) kindsOn;
+ final ValueChanged<DateTime> onPick;
+ final ValueChanged<DateTime> onHold;
+ final ValueChanged<int> onMonth;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final today = DateTime.now();
+ final first = DateTime(month.year, month.month);
+ final days = DateTime(month.year, month.month + 1, 0).day;
+ final lead = (first.weekday - t.firstWeekday + 7) % 7;
+
+ return Column(
+ children: [
+ Row(
+ children: [
+ _arrow(gc, PhosphorIconsBold.caretLeft, t.notePrevMonth, () => onMonth(-1)),
+ Expanded(
+ child: Text(t.monthYear(month),
+ textAlign: TextAlign.center,
+ style: AppTheme.d(15, weight: FontWeight.w700, color: gc.text)),
+ ),
+ _arrow(gc, PhosphorIconsBold.caretRight, t.noteNextMonth, () => onMonth(1)),
+ ],
+ ),
+ const SizedBox(height: 14),
+ Row(
+ children: [
+ for (int i = 0; i < 7; i++)
+ Expanded(
+ child: Text(t.weekdayInitial((t.firstWeekday + i - 1) % 7 + 1).toUpperCase(),
+ textAlign: TextAlign.center,
+ style: AppTheme.d(10.5,
+ weight: FontWeight.w600, color: gc.textTertiary, letterSpacing: 1)),
+ ),
+ ],
+ ),
+ const SizedBox(height: 8),
+ for (int row = 0; row * 7 < lead + days; row++)
+ Row(
+ children: [
+ for (int col = 0; col < 7; col++)
+ Expanded(
+ child: () {
+ final n = row * 7 + col - lead + 1;
+ if (n < 1 || n > days) return const SizedBox(height: 46);
+ return _cell(gc, DateTime(month.year, month.month, n), today);
+ }(),
+ ),
+ ],
+ ),
+ ],
+ );
+ }
+
+ Widget _arrow(GymColors gc, IconData icon, String label, VoidCallback onTap) => Semantics(
+ button: true,
+ label: label,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: Container(
+ width: 34,
+ height: 34,
+ decoration: BoxDecoration(color: gc.bgRaised2, shape: BoxShape.circle),
+ child: Icon(icon, size: 13, color: gc.text),
+ ),
+ ),
+ );
+
+ Widget _cell(GymColors gc, DateTime day, DateTime today) {
+ final kinds = kindsOn(day);
+ final isToday = day.year == today.year && day.month == today.month && day.day == today.day;
+ final on = day == DateTime(selected.year, selected.month, selected.day);
+
+ return Semantics(
+ button: true,
+ selected: on,
+ label: t.fullDate(day),
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => onPick(day),
+ onLongPress: () => onHold(day),
+ child: Container(
+ height: 46,
+ margin: const EdgeInsets.all(1.5),
+ decoration: BoxDecoration(
+ color: on ? gc.emberSoft : Colors.transparent,
+ borderRadius: BorderRadius.circular(13),
+ border: Border.all(color: on ? gc.ember : Colors.transparent),
+ ),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text('${day.day}',
+ style: AppTheme.d(13.5,
+ weight: isToday || on ? FontWeight.w700 : FontWeight.w500,
+ color: on
+ ? gc.text
+ : isToday
+ ? gc.ember
+ : gc.textSecondary)),
+ const SizedBox(height: 4),
+ SizedBox(
+ height: 5,
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ for (final k in kinds.take(3)) ...[
+ if (k != kinds.first) const SizedBox(width: 3),
+ Container(
+ width: 5,
+ height: 5,
+ decoration: BoxDecoration(
+ color: noteKindColor(gc, k),
+ shape: BoxShape.circle,
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+Future<void> showNoteDaySheet(BuildContext context, DateTime day) async {
+ final gc = context.gc;
+ final kind = await showModalBottomSheet<NoteKind>(
+ context: context,
+ backgroundColor: Colors.transparent,
+ builder: (sheet) => Container(
+ padding: const EdgeInsets.fromLTRB(20, 12, 20, 26),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Center(
+ child: Container(
+ width: 40,
+ height: 4,
+ decoration:
+ BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(2)),
+ ),
+ ),
+ const SizedBox(height: 18),
+ Text(noteDayLabel(day).toUpperCase(),
+ style: AppTheme.d(13, weight: FontWeight.w700, color: gc.text, letterSpacing: 2)),
+ const SizedBox(height: 3),
+ Text(t.fullDate(day), style: AppTheme.s(12.5, color: gc.textTertiary)),
+ const SizedBox(height: 18),
+ for (final k in NoteKind.values) ...[
+ if (k != NoteKind.values.first) const SizedBox(height: 8),
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => Navigator.of(sheet).pop(k),
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
+ decoration: BoxDecoration(
+ color: gc.bgRaised2,
+ borderRadius: BorderRadius.circular(16),
+ border: Border.all(color: gc.border),
+ ),
+ child: Row(
+ children: [
+ Icon(noteKindIcon(k), size: 18, color: noteKindColor(gc, k)),
+ const SizedBox(width: 14),
+ Expanded(
+ child: Text(noteKindLabel(k),
+ style: AppTheme.s(14, weight: FontWeight.w600, color: gc.text)),
+ ),
+ Icon(PhosphorIconsRegular.caretRight, size: 14, color: gc.textTertiary),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ );
+ if (kind != null) fit.openNoteEditor(exerciseId: fit.noteScope, date: day, kind: kind);
+}
+
+class NoteKindBadge extends StatelessWidget {
+ const NoteKindBadge({super.key, required this.kind, this.compact = false});
+
+ final NoteKind kind;
+ final bool compact;
+
+ @override
+ Widget build(BuildContext context) {
+ final color = noteKindColor(context.gc, kind);
+ return Container(
+ padding: EdgeInsets.symmetric(horizontal: compact ? 7 : 9, vertical: compact ? 3 : 4),
+ decoration: BoxDecoration(
+ color: color.withValues(alpha: 0.14),
+ borderRadius: BorderRadius.circular(8),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(noteKindIcon(kind), size: compact ? 10 : 12, color: color),
+ SizedBox(width: compact ? 4 : 5),
+ Text(noteKindLabel(kind).toUpperCase(),
+ style: AppTheme.d(compact ? 9.5 : 10.5,
+ weight: FontWeight.w600, color: color, letterSpacing: 1)),
+ ],
+ ),
+ );
+ }
+}
+
+class NoteKindPicker extends StatelessWidget {
+ const NoteKindPicker({super.key, required this.selected, required this.onChanged});
+
+ final NoteKind selected;
+ final ValueChanged<NoteKind> onChanged;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Row(
+ children: [
+ for (final kind in NoteKind.values) ...[
+ if (kind != NoteKind.values.first) const SizedBox(width: 8),
+ Expanded(
+ child: Semantics(
+ button: true,
+ selected: selected == kind,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => onChanged(kind),
+ child: AnimatedContainer(
+ duration: const Duration(milliseconds: 160),
+ padding: const EdgeInsets.symmetric(vertical: 12),
+ decoration: BoxDecoration(
+ color: selected == kind
+ ? noteKindColor(gc, kind).withValues(alpha: 0.14)
+ : gc.bgRaised,
+ borderRadius: BorderRadius.circular(14),
+ border: Border.all(
+ color: selected == kind ? noteKindColor(gc, kind) : gc.border,
+ width: selected == kind ? 1.4 : 1,
+ ),
+ ),
+ child: Column(
+ children: [
+ Icon(noteKindIcon(kind),
+ size: 18,
+ color: selected == kind ? noteKindColor(gc, kind) : gc.textTertiary),
+ const SizedBox(height: 6),
+ FittedBox(
+ fit: BoxFit.scaleDown,
+ child: Text(
+ noteKindLabel(kind),
+ maxLines: 1,
+ style: AppTheme.s(11.5,
+ weight: FontWeight.w600,
+ color: selected == kind
+ ? noteKindColor(gc, kind)
+ : gc.textSecondary),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ],
+ );
+ }
+}
+
+class NoteFilterBar extends StatelessWidget {
+ const NoteFilterBar({
+ super.key,
+ required this.selected,
+ required this.counts,
+ required this.onPick,
+ });
+
+ final NoteKind? selected;
+ final Map<NoteKind, int> counts;
+ final ValueChanged<NoteKind?> onPick;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+
+ Widget chip({
+ required String label,
+ required Color color,
+ required bool on,
+ required VoidCallback onTap,
+ }) =>
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: Container(
+ margin: const EdgeInsets.only(right: 8),
+ padding: const EdgeInsets.symmetric(horizontal: 13, vertical: 8),
+ decoration: BoxDecoration(
+ color: on ? color.withValues(alpha: 0.16) : gc.bgRaised,
+ borderRadius: BorderRadius.circular(100),
+ border: Border.all(color: on ? color : gc.border),
+ ),
+ child: Center(
+ child: Text(label,
+ style: AppTheme.s(12.5,
+ weight: FontWeight.w600, color: on ? color : gc.textSecondary)),
+ ),
+ ),
+ );
+
+ return SizedBox(
+ height: 38,
+ child: ListView(
+ scrollDirection: Axis.horizontal,
+ children: [
+ chip(
+ label: t.noteFilterAll,
+ color: gc.ember,
+ on: selected == null,
+ onTap: () => onPick(null),
+ ),
+ for (final kind in NoteKind.values)
+ if ((counts[kind] ?? 0) > 0)
+ chip(
+ label: '${noteKindLabel(kind)} ${counts[kind]}',
+ color: noteKindColor(gc, kind),
+ on: selected == kind,
+ onTap: () => onPick(kind),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class NoteCard extends StatelessWidget {
+ const NoteCard({
+ super.key,
+ required this.note,
+ this.showExercise = true,
+ this.showDate = true,
+ this.onTap,
+ });
+
+ final GymNote note;
+ final bool showExercise;
+ final bool showDate;
+ final VoidCallback? onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final color = noteKindColor(gc, note.kind);
+ final exercise = showExercise ? fit.noteExerciseName(note) : '';
+ final day = showDate ? noteDayLabel(note.date) : '';
+ final meta = [day, exercise].where((p) => p.isNotEmpty).join(' · ');
+
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap ?? () => fit.openNoteEditor(id: note.id),
+ child: Container(
+ margin: const EdgeInsets.only(bottom: 10),
+ clipBehavior: Clip.antiAlias,
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(18),
+ ),
+ child: Stack(
+ children: [
+ Positioned.fill(child: CustomPaint(painter: _NoteRail(color))),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(17, 13, 14, 14),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ NoteKindBadge(kind: note.kind, compact: true),
+ const SizedBox(width: 8),
+ Expanded(
+ child: Text(
+ meta,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.right,
+ style: AppTheme.s(11.5, color: gc.textTertiary),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 9),
+ Text(note.title,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.s(15, weight: FontWeight.w600, color: gc.text, height: 1.3)),
+ if (note.body.isNotEmpty) ...[
+ const SizedBox(height: 4),
+ Text(note.body,
+ maxLines: 3,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.s(13, color: gc.textSecondary, height: 1.4)),
+ ],
+ if (note.media.isNotEmpty) ...[
+ const SizedBox(height: 12),
+ NoteMediaStrip(media: note.media),
+ ],
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class _NoteRail extends CustomPainter {
+ _NoteRail(this.color);
+
+ final Color color;
+ static const double _w = 3;
+ static const double _r = 18;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final fade = LinearGradient(
+ begin: Alignment.centerLeft,
+ end: Alignment.centerRight,
+ colors: [color, color, color.withValues(alpha: 0)],
+ stops: const [0, 0.06, 0.26],
+ ).createShader(Offset.zero & size);
+
+ canvas.drawRRect(
+ RRect.fromRectAndRadius(
+ Rect.fromLTWH(_w / 2, _w / 2, size.width - _w, size.height - _w),
+ const Radius.circular(_r - _w / 2),
+ ),
+ Paint()
+ ..shader = fade
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = _w,
+ );
+ }
+
+ @override
+ bool shouldRepaint(_NoteRail o) => o.color != color;
+}
+
+class NoteMediaStrip extends StatelessWidget {
+ const NoteMediaStrip({super.key, required this.media, this.size = 64, this.max = 4});
+
+ final List<String> media;
+ final double size;
+ final int max;
+
+ @override
+ Widget build(BuildContext context) {
+ final shown = media.take(max).toList();
+ final extra = media.length - shown.length;
+ return SizedBox(
+ height: size,
+ child: Row(
+ children: [
+ for (int i = 0; i < shown.length; i++) ...[
+ if (i > 0) const SizedBox(width: 8),
+ GestureDetector(
+ onTap: () => showNoteMedia(context, media, i),
+ child: NoteThumb(
+ name: shown[i],
+ size: size,
+ badge: i == shown.length - 1 && extra > 0 ? '+$extra' : null,
+ ),
+ ),
+ ],
+ ],
+ ),
+ );
+ }
+}
+
+class NoteThumb extends StatelessWidget {
+ const NoteThumb({super.key, required this.name, this.size = 64, this.badge, this.onRemove});
+
+ final String name;
+ final double size;
+ final String? badge;
+ final VoidCallback? onRemove;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final path = MediaStore.pathFor(name);
+
+ Widget inner;
+ if (path == null) {
+ inner = Icon(PhosphorIconsRegular.imageSquare, size: size * 0.34, color: gc.textTertiary);
+ } else if (MediaStore.isVideo(name)) {
+ inner = Icon(PhosphorIconsFill.playCircle, size: size * 0.38, color: gc.textSecondary);
+ } else {
+ inner = Image.file(
+ File(path),
+ width: size,
+ height: size,
+ fit: BoxFit.cover,
+ gaplessPlayback: true,
+ errorBuilder: (_, _, _) =>
+ Icon(PhosphorIconsRegular.imageSquare, size: size * 0.34, color: gc.textTertiary),
+ );
+ }
+
+ return SizedBox(
+ width: size,
+ height: size,
+ child: Stack(
+ clipBehavior: Clip.none,
+ children: [
+ Positioned.fill(
+ child: Container(
+ decoration: BoxDecoration(
+ color: gc.bgRaised2,
+ borderRadius: BorderRadius.circular(12),
+ border: Border.all(color: gc.border),
+ ),
+ clipBehavior: Clip.antiAlias,
+ child: Center(child: inner),
+ ),
+ ),
+ if (badge != null)
+ Positioned.fill(
+ child: Container(
+ decoration: BoxDecoration(
+ color: const Color(0xA6000000),
+ borderRadius: BorderRadius.circular(12),
+ ),
+ alignment: Alignment.center,
+ child: Text(badge!,
+ style: AppTheme.d(14, weight: FontWeight.w700, color: Colors.white)),
+ ),
+ ),
+ if (onRemove != null)
+ Positioned(
+ top: -6,
+ right: -6,
+ child: Semantics(
+ button: true,
+ label: t.noteRemoveMedia,
+ child: GestureDetector(
+ onTap: onRemove,
+ child: Container(
+ width: 24,
+ height: 24,
+ decoration: BoxDecoration(
+ color: gc.bgRaised2,
+ shape: BoxShape.circle,
+ border: Border.all(color: gc.border),
+ ),
+ child: Icon(PhosphorIconsBold.x, size: 11, color: gc.text),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+Future<void> showNoteMedia(BuildContext context, List<String> media, int index) => showDialog(
+ context: context,
+ barrierColor: const Color(0xF2000000),
+ builder: (_) => _MediaViewer(media: media, start: index),
+ );
+
+class _MediaViewer extends StatefulWidget {
+ const _MediaViewer({required this.media, required this.start});
+
+ final List<String> media;
+ final int start;
+
+ @override
+ State<_MediaViewer> createState() => _MediaViewerState();
+}
+
+class _MediaViewerState extends State<_MediaViewer> {
+ late final PageController _pages = PageController(initialPage: widget.start);
+ late int _index = widget.start;
+
+ @override
+ void dispose() {
+ _pages.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Dialog.fullscreen(
+ backgroundColor: Colors.transparent,
+ child: Stack(
+ children: [
+ PageView.builder(
+ controller: _pages,
+ itemCount: widget.media.length,
+ onPageChanged: (i) => setState(() => _index = i),
+ itemBuilder: (_, i) {
+ final name = widget.media[i];
+ final path = MediaStore.pathFor(name);
+ if (path == null) return const SizedBox.shrink();
+ if (MediaStore.isVideo(name)) {
+ return _FullVideo(key: ValueKey(path), path: path);
+ }
+ return InteractiveViewer(
+ maxScale: 5,
+ child: Center(child: Image.file(File(path), fit: BoxFit.contain)),
+ );
+ },
+ ),
+ Positioned(
+ top: 0,
+ left: 0,
+ right: 0,
+ child: SafeArea(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
+ child: Row(
+ children: [
+ Semantics(
+ button: true,
+ label: t.cancel,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => Navigator.of(context).pop(),
+ child: const Padding(
+ padding: EdgeInsets.all(10),
+ child: Icon(PhosphorIconsBold.x, size: 20, color: Colors.white),
+ ),
+ ),
+ ),
+ const Spacer(),
+ if (widget.media.length > 1)
+ Text('${_index + 1}/${widget.media.length}',
+ style: AppTheme.d(14, weight: FontWeight.w600, color: Colors.white)),
+ const SizedBox(width: 10),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _FullVideo extends StatefulWidget {
+ const _FullVideo({super.key, required this.path});
+ final String path;
+
+ @override
+ State<_FullVideo> createState() => _FullVideoState();
+}
+
+class _FullVideoState extends State<_FullVideo> {
+ VideoPlayerController? _c;
+ bool _failed = false;
+
+ @override
+ void initState() {
+ super.initState();
+ _load();
+ }
+
+ Future<void> _load() async {
+ try {
+ final c = VideoPlayerController.file(File(widget.path));
+ await c.initialize();
+ await c.setLooping(true);
+ await c.play();
+ if (!mounted) {
+ c.dispose();
+ return;
+ }
+ setState(() => _c = c);
+ } catch (_) {
+ if (mounted) setState(() => _failed = true);
+ }
+ }
+
+ @override
+ void dispose() {
+ _c?.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final c = _c;
+ if (_failed) {
+ return const Center(
+ child: Icon(PhosphorIconsRegular.videoCamera, size: 48, color: Colors.white38));
+ }
+ if (c == null) {
+ return const Center(
+ child: SizedBox(width: 26, height: 26, child: CircularProgressIndicator(strokeWidth: 2)),
+ );
+ }
+ return GestureDetector(
+ onTap: () => setState(() => c.value.isPlaying ? c.pause() : c.play()),
+ child: Center(
+ child: AspectRatio(aspectRatio: c.value.aspectRatio, child: VideoPlayer(c)),
+ ),
+ );
+ }
+}
diff --git a/test/exercise_notes_test.dart b/test/exercise_notes_test.dart
index a835ce6..d5ad599 100644
--- a/test/exercise_notes_test.dart
+++ b/test/exercise_notes_test.dart
@@ -1,22 +1,26 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:gymmane/l10n/l10n.dart';
+import 'package:gymmane/models/note.dart';
import 'package:gymmane/screens/exercise_detail_screen.dart';
+import 'package:gymmane/screens/notes_screen.dart';
import 'package:gymmane/state/fit_state.dart';
import 'package:gymmane/theme/app_theme.dart';
+import 'package:gymmane/widgets/note_kit.dart';
-Widget _host() => MaterialApp(
+Widget _host(Widget Function() screen) => MaterialApp(
theme: AppTheme.dark,
home: AnimatedBuilder(
animation: fit,
-
- builder: (_, _) => Scaffold(body: ExerciseDetailScreen()),
+ builder: (_, _) => Scaffold(body: screen()),
),
);
const _exId = 'barbell-bench-press';
void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
late String exId;
Future<void> tapVisible(WidgetTester tester, Finder f) async {
@@ -29,76 +33,133 @@ void main() {
setUp(() {
setAppLanguage('en');
exId = fit.allExercises.any((e) => e.id == _exId) ? _exId : fit.allExercises.first.id;
- fit.exNotes.remove(exId);
+ fit.notes.clear();
+ fit.noteScope = '';
+ fit.noteFilter = null;
fit.openExercise(exId);
});
tearDown(() {
- fit.exNotes.remove(exId);
+ fit.notes.clear();
fit.persistNow();
});
- void addNotes(int n) {
+ void addNotes(int n, {NoteKind kind = NoteKind.note, String? on}) {
for (int i = 1; i <= n; i++) {
- fit.addNote(exId, 'nota $i');
+ fit.saveNote(
+ exerciseId: on ?? exId,
+ date: DateTime.now().subtract(Duration(days: n - i)),
+ kind: kind,
+ text: 'nota $i',
+ );
}
fit.persistNow();
}
- testWidgets('a handful of notes shows them all, with no toggle to get in the way',
- (tester) async {
+ testWidgets('the exercise sheet counts its notes instead of piling them up', (tester) async {
addNotes(3);
- await tester.pumpWidget(_host());
- expect(find.text('nota 1'), findsOneWidget);
- expect(find.text('nota 3'), findsOneWidget);
- expect(find.textContaining('note', findRichText: true), findsNothing,
- reason: 'sin desbordar no hay nada que desplegar');
+ await tester.pumpWidget(_host(ExerciseDetailScreen.new));
+
+ expect(find.text(t.noteCount(3)), findsOneWidget);
+ expect(find.text('nota 3'), findsNothing);
+ expect(find.text('nota 1'), findsNothing);
+ expect(find.text(t.noteNoneForExercise), findsNothing);
});
- testWidgets('past the limit only the newest survive on screen', (tester) async {
+ testWidgets('with none written the sheet says so instead of showing an empty list',
+ (tester) async {
+ await tester.pumpWidget(_host(ExerciseDetailScreen.new));
+ expect(find.text(t.noteNoneForExercise), findsOneWidget);
+ });
+
+ testWidgets('the notes button opens the journal of that exercise', (tester) async {
addNotes(10);
- await tester.pumpWidget(_host());
+ await tester.pumpWidget(_host(ExerciseDetailScreen.new));
- expect(find.text('nota 10'), findsOneWidget);
- expect(find.text('nota 8'), findsOneWidget);
- expect(find.text('nota 7'), findsNothing, reason: 'la cuarta ya no cabe en el resumen');
- expect(find.text('nota 1'), findsNothing);
+ expect(find.text('nota 10'), findsNothing);
+
+ await tapVisible(tester, find.text(t.notes));
+ expect(fit.route, 'notes');
+ expect(fit.noteScope, exId);
+ expect(fit.notesAllView, isFalse);
});
- testWidgets('the toggle opens every note and closes back down', (tester) async {
- addNotes(10);
- await tester.pumpWidget(_host());
+ testWidgets('the journal scoped to one exercise leaves the rest out', (tester) async {
+ final other = fit.allExercises.firstWhere((e) => e.id != exId).id;
+ addNotes(2);
+ fit.saveNote(
+ exerciseId: other, date: DateTime.now(), kind: NoteKind.note, text: 'de otro sitio');
+ fit.persistNow();
- await tapVisible(tester, find.text(t.showAllNotes(10)));
- expect(find.text('nota 1'), findsOneWidget, reason: 'la más vieja tiene que ser alcanzable');
+ fit.goNotes(exerciseId: exId, all: true);
+ await tester.pumpWidget(_host(NotesScreen.new));
- await tapVisible(tester, find.text(t.showFewerNotes));
- expect(find.text('nota 1'), findsNothing);
- expect(find.text(t.showAllNotes(10)), findsOneWidget);
+ expect(find.text('nota 1'), findsOneWidget);
+ expect(find.text('de otro sitio'), findsNothing);
});
- testWidgets('opening the notes does not stretch the page without bound', (tester) async {
- addNotes(40);
- await tester.pumpWidget(_host());
- await tapVisible(tester, find.text(t.showAllNotes(40)));
+ testWidgets('the kind filter narrows the journal down', (tester) async {
+ addNotes(2);
+ fit.saveNote(
+ exerciseId: exId, date: DateTime.now(), kind: NoteKind.pain, text: 'me tira el hombro');
+ fit.persistNow();
- expect(find.text('nota 1'), findsOneWidget, reason: 'se ha desplegado de verdad');
+ fit.goNotes(all: true);
+ await tester.pumpWidget(_host(NotesScreen.new));
+ expect(find.text('nota 1'), findsOneWidget);
- final box = tester.getSize(find.byType(Scrollbar));
- expect(box.height, lessThanOrEqualTo(260.0),
- reason: 'las notas scrollean dentro de su caja en vez de estirar la ficha');
+ await tapVisible(tester, find.textContaining(noteKindLabel(NoteKind.pain)).first);
+ expect(find.text('me tira el hombro'), findsOneWidget);
+ expect(find.text('nota 1'), findsNothing);
});
- testWidgets('deleting hits the note you pointed at, not another one', (tester) async {
+ test('deleting hits the note you pointed at, not another one', () {
addNotes(5);
- await tester.pumpWidget(_host());
- expect(find.text('nota 5'), findsOneWidget);
+ final newest = fit.notesFor(exId).first;
+ expect(newest.text, 'nota 5');
- fit.deleteNote(exId, 0);
- fit.persistNow();
- await tester.pumpAndSettle();
+ fit.deleteNote(newest.id);
+ expect(fit.notesFor(exId).map((n) => n.text), isNot(contains('nota 5')));
+ expect(fit.notesFor(exId).first.text, 'nota 4');
+ });
+
+ test('editing a note keeps its place instead of adding a second one', () {
+ addNotes(1);
+ final note = fit.notes.single;
+ fit.saveNote(
+ id: note.id,
+ exerciseId: exId,
+ date: note.date,
+ kind: NoteKind.plan,
+ text: 'subir a 82.5',
+ );
+
+ expect(fit.notes, hasLength(1));
+ expect(fit.notes.single.kind, NoteKind.plan);
+ expect(fit.notes.single.text, 'subir a 82.5');
+ });
+
+ test('an empty note is not worth saving', () {
+ fit.saveNote(exerciseId: exId, date: DateTime.now(), kind: NoteKind.note, text: ' ');
+ expect(fit.notes, isEmpty);
+ });
+
+ test('the title is the first line and the body the rest', () {
+ fit.saveNote(
+ exerciseId: exId,
+ date: DateTime.now(),
+ kind: NoteKind.note,
+ text: 'Codos dentro\ny bajar despacio');
+ final n = fit.notes.single;
+ expect(n.title, 'Codos dentro');
+ expect(n.body, 'y bajar despacio');
+ });
- expect(find.text('nota 5'), findsNothing);
- expect(find.text('nota 4'), findsOneWidget);
+ test('notes with no exercise live in the journal all the same', () {
+ fit.saveNote(exerciseId: '', date: DateTime.now(), kind: NoteKind.done, text: 'peso a 74 kg');
+ expect(fit.notes.single.isGeneral, true);
+ expect(fit.notesFor(exId), isEmpty);
+ fit.noteScope = '';
+ expect(fit.notesInScope, hasLength(1));
});
}
diff --git a/test/note_calendar_test.dart b/test/note_calendar_test.dart
new file mode 100644
index 0000000..7435296
--- /dev/null
+++ b/test/note_calendar_test.dart
@@ -0,0 +1,126 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:gymmane/l10n/l10n.dart';
+import 'package:gymmane/models/note.dart';
+import 'package:gymmane/screens/notes_screen.dart';
+import 'package:gymmane/services/local_store.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()),
+ ),
+ );
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ setUp(() async {
+ SharedPreferences.setMockInitialValues({});
+ await Store.instance.init();
+ setAppLanguage('es');
+ fit.notes.clear();
+ fit.goNotes();
+ });
+
+ tearDown(() {
+ fit.notes.clear();
+ fit.persistNow();
+ });
+
+ void note(DateTime day, String text, {NoteKind kind = NoteKind.note}) {
+ fit.saveNote(exerciseId: '', date: day, kind: kind, text: text);
+ fit.persistNow();
+ }
+
+ test('the notes of a day are the ones written that day', () {
+ final today = DateTime.now();
+ note(today, 'de hoy');
+ note(today.subtract(const Duration(days: 1)), 'de ayer');
+
+ expect(fit.notesOn(today).map((n) => n.text), ['de hoy']);
+ expect(fit.notesOn(today.subtract(const Duration(days: 1))).map((n) => n.text), ['de ayer']);
+ });
+
+ test('a day carries one dot per kind, never repeated', () {
+ final day = DateTime.now();
+ note(day, 'una', kind: NoteKind.note);
+ note(day, 'otra', kind: NoteKind.note);
+ note(day, 'molesta', kind: NoteKind.pain);
+
+ expect(fit.noteKindsOn(day), [NoteKind.note, NoteKind.pain]);
+ expect(fit.noteKindsOn(day.subtract(const Duration(days: 2))), isEmpty);
+ });
+
+ test('saving a note lands on its own day and month', () {
+ final day = DateTime(2026, 3, 14);
+ note(day, 'del catorce');
+
+ expect(fit.noteDay, DateTime(2026, 3, 14));
+ expect(fit.noteMonth, DateTime(2026, 3));
+ });
+
+ test('the month moves without dragging the selected day along', () {
+ fit.selectNoteDay(DateTime(2026, 3, 14));
+ fit.showNoteMonth(-1);
+
+ expect(fit.noteMonth, DateTime(2026, 2));
+ expect(fit.noteDay, DateTime(2026, 3, 14));
+ });
+
+ testWidgets('the calendar shows the day you picked, not the rest', (tester) async {
+ final today = DateTime.now();
+ note(today, 'de hoy');
+ note(today.subtract(const Duration(days: 2)), 'de anteayer');
+ fit.selectNoteDay(today);
+
+ await tester.pumpWidget(_host(NotesScreen.new));
+ expect(find.text('de hoy'), findsOneWidget);
+ expect(find.text('de anteayer'), findsNothing);
+
+ fit.selectNoteDay(today.subtract(const Duration(days: 2)));
+ await tester.pumpAndSettle();
+ expect(find.text('de anteayer'), findsOneWidget);
+ expect(find.text('de hoy'), findsNothing);
+ });
+
+ testWidgets('tapping a day in the grid selects it', (tester) async {
+ fit.selectNoteDay(DateTime(2026, 3, 14));
+ await tester.pumpWidget(_host(NotesScreen.new));
+
+ await tester.tap(find.text('21').first);
+ await tester.pumpAndSettle();
+ expect(fit.noteDay, DateTime(2026, 3, 21));
+ });
+
+ testWidgets('the list view puts every day on the page, split by day', (tester) async {
+ final today = DateTime.now();
+ note(today, 'de hoy');
+ note(today.subtract(const Duration(days: 1)), 'de ayer');
+
+ fit.setNotesAllView(true);
+ await tester.pumpWidget(_host(NotesScreen.new));
+
+ expect(find.text('de hoy'), findsOneWidget);
+ expect(find.text('de ayer'), findsOneWidget);
+ expect(find.text(t.noteToday.toUpperCase()), findsOneWidget);
+ expect(find.text(t.noteYesterday.toUpperCase()), findsOneWidget);
+ });
+
+ testWidgets('back from the list view lands on the calendar, not out of the journal',
+ (tester) async {
+ fit.goNotes(all: true);
+ await tester.pumpWidget(_host(NotesScreen.new));
+
+ fit.backFromNotes();
+ expect(fit.route, 'notes');
+ expect(fit.notesAllView, false);
+
+ fit.backFromNotes();
+ expect(fit.route, isNot('notes'));
+ });
+}