Skip to content

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

Show exercise notes during the workout

InlitX9850c69c2edc
diff --git a/lib/models/note.dart b/lib/models/note.dart
index 0d06916..2500bb8 100644
--- a/lib/models/note.dart
+++ b/lib/models/note.dart
@@ -9,6 +9,7 @@ class GymNote {
required this.text,
this.media = const [],
required this.createdAt,
+ this.pinned = false,
});
final String id;
@@ -18,6 +19,7 @@ class GymNote {
final String text;
final List<String> media;
final DateTime createdAt;
+ final bool pinned;
bool get isGeneral => exerciseId.isEmpty;
@@ -34,6 +36,7 @@ class GymNote {
NoteKind? kind,
String? text,
List<String>? media,
+ bool? pinned,
}) =>
GymNote(
id: id,
@@ -43,6 +46,7 @@ class GymNote {
text: text ?? this.text,
media: media ?? this.media,
createdAt: createdAt,
+ pinned: pinned ?? this.pinned,
);
Map<String, dynamic> toJson() => {
@@ -53,6 +57,7 @@ class GymNote {
't': text,
if (media.isNotEmpty) 'm': media,
'c': createdAt.toIso8601String(),
+ if (pinned) 'p': true,
};
factory GymNote.fromJson(Map<String, dynamic> j) {
@@ -65,6 +70,7 @@ class GymNote {
text: (j['t'] ?? '') as String,
media: ((j['m'] as List?) ?? const []).cast<String>(),
createdAt: created,
+ pinned: j['p'] == true,
);
}
}
diff --git a/lib/screens/note_edit_screen.dart b/lib/screens/note_edit_screen.dart
index 9fc7ab8..7cc6e2d 100644
--- a/lib/screens/note_edit_screen.dart
+++ b/lib/screens/note_edit_screen.dart
@@ -31,6 +31,7 @@ class _NoteEditScreenState extends State<NoteEditScreen> {
late DateTime _date = _note?.date ?? fit.noteDraftDate;
late String _exerciseId = _note?.exerciseId ?? fit.noteDraftExercise;
late final List<String> _media = [...?_note?.media];
+ late bool _pinned = _note?.pinned ?? false;
final List<String> _added = [];
bool _saved = false;
@@ -55,6 +56,7 @@ class _NoteEditScreenState extends State<NoteEditScreen> {
kind: _kind,
text: _text.text,
media: _media,
+ pinned: _pinned,
);
fit.closeNoteEditor();
}
@@ -192,6 +194,17 @@ class _NoteEditScreenState extends State<NoteEditScreen> {
),
onTap: _pickExercise,
),
+ if (exercise != null) ...[
+ Divider(height: 1, thickness: 1, indent: 16, endIndent: 16, color: gc.border),
+ _row(
+ gc,
+ icon: PhosphorIconsRegular.pushPin,
+ label: t.notePinWorkout,
+ value: '',
+ trailing: TinySwitch(on: _pinned),
+ onTap: () => setState(() => _pinned = !_pinned),
+ ),
+ ],
]),
),
),
diff --git a/lib/state/notes_state.dart b/lib/state/notes_state.dart
index 2493022..efa62ab 100644
--- a/lib/state/notes_state.dart
+++ b/lib/state/notes_state.dart
@@ -106,6 +106,7 @@ mixin NotesState on FitCore, LibraryState {
required NoteKind kind,
required String text,
List<String> media = const [],
+ bool? pinned,
}) {
final body = text.trim();
if (body.isEmpty) return;
@@ -121,6 +122,7 @@ mixin NotesState on FitCore, LibraryState {
text: body,
media: [...media],
createdAt: DateTime.now(),
+ pinned: (pinned ?? false) && exerciseId.isNotEmpty,
));
} else {
final old = notes[index];
@@ -133,6 +135,7 @@ mixin NotesState on FitCore, LibraryState {
kind: kind,
text: body,
media: [...media],
+ pinned: exerciseId.isEmpty ? false : pinned,
);
}
noteDay = day;
@@ -141,6 +144,30 @@ mixin NotesState on FitCore, LibraryState {
notifyListeners();
}
+ void setNotePinned(String id, bool on) {
+ final index = notes.indexWhere((n) => n.id == id);
+ if (index < 0 || notes[index].pinned == on || notes[index].exerciseId.isEmpty) return;
+ notes[index] = notes[index].copyWith(pinned: on);
+ _persist();
+ notifyListeners();
+ }
+
+ List<GymNote> workoutNotesFor(String exerciseId) {
+ if (exerciseId.isEmpty) return const [];
+ final today = _dayKey(DateTime.now());
+ final mine = notesFor(exerciseId);
+ DateTime? lastDone;
+ for (final s in sessions) {
+ final day = _dayKey(s.day);
+ if (!day.isBefore(today) || !s.exercises.any((e) => e.id == exerciseId)) continue;
+ if (lastDone == null || day.isAfter(lastDone)) lastDone = day;
+ }
+ final since = lastDone ?? today.subtract(const Duration(days: 30));
+ final next = mine.where((n) =>
+ !n.pinned && n.kind == NoteKind.plan && !n.date.isBefore(since));
+ return [...mine.where((n) => n.pinned), ...next.take(1)];
+ }
+
void deleteNote(String id) {
final index = notes.indexWhere((n) => n.id == id);
if (index < 0) return;
diff --git a/lib/widgets/note_kit.dart b/lib/widgets/note_kit.dart
index da2f7c1..554d918 100644
--- a/lib/widgets/note_kit.dart
+++ b/lib/widgets/note_kit.dart
@@ -418,6 +418,13 @@ class NoteCard extends StatelessWidget {
Row(
children: [
NoteKindBadge(kind: note.kind, compact: true),
+ if (note.pinned) ...[
+ const SizedBox(width: 6),
+ Semantics(
+ label: t.workoutNoteEvery,
+ child: Icon(PhosphorIconsFill.pushPin, size: 13, color: gc.accent),
+ ),
+ ],
const SizedBox(width: 8),
Expanded(
child: Text(
diff --git a/lib/widgets/workout_notes.dart b/lib/widgets/workout_notes.dart
new file mode 100644
index 0000000..4996166
--- /dev/null
+++ b/lib/widgets/workout_notes.dart
@@ -0,0 +1,297 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';
+
+import '../l10n/l10n.dart';
+import '../models/note.dart';
+import '../state/fit_state.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+import '../widgets/dialogs.dart';
+import 'glass.dart';
+import 'ui_kit.dart';
+
+class WorkoutNoteStrip extends StatelessWidget {
+ const WorkoutNoteStrip({super.key, required this.exerciseId, this.onDark = false});
+
+ final String exerciseId;
+ final bool onDark;
+
+ @override
+ Widget build(BuildContext context) {
+ final notes = fit.workoutNotesFor(exerciseId);
+ if (notes.isEmpty) return const SizedBox.shrink();
+ final gc = context.gc;
+ return Semantics(
+ button: true,
+ label: t.workoutNotesTitle,
+ child: Pressable(
+ scale: 0.98,
+ onTap: () => showWorkoutNotesSheet(context, exerciseId),
+ child: Container(
+ width: double.infinity,
+ padding: const EdgeInsets.fromLTRB(10, 8, 12, 8),
+ decoration: BoxDecoration(
+ color: onDark ? gc.bgRaised2 : gc.bgRaised,
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ for (var i = 0; i < notes.length; i++) ...[
+ if (i > 0) const SizedBox(height: 6),
+ Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Padding(
+ padding: const EdgeInsets.only(top: 1.5),
+ child: Icon(_iconOf(notes[i]), size: 13, color: gc.accent),
+ ),
+ const SizedBox(width: 8),
+ Expanded(
+ child: Text(notes[i].text.trim().replaceAll(RegExp(r'\s*\n\s*'), ' · '),
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(12.5, weight: FontWeight.w600, color: gc.textSecondary, height: 1.3)),
+ ),
+ ]),
+ ],
+ ]),
+ ),
+ ),
+ );
+ }
+}
+
+IconData _iconOf(GymNote n) => n.pinned ? PhosphorIconsFill.pushPin : PhosphorIconsFill.arrowBendDownRight;
+
+Widget _sheetBox(BuildContext context, List<Widget> children) {
+ final gc = context.gc;
+ return Padding(
+ padding: EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom),
+ child: Container(
+ constraints: BoxConstraints(maxHeight: MediaQuery.sizeOf(context).height * 0.85),
+ padding: sheetPad(context),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),
+ ),
+ child: SingleChildScrollView(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [const SheetHandle(), const SizedBox(height: 16), ...children],
+ ),
+ ),
+ ),
+ );
+}
+
+String _exerciseTitle(String id) {
+ final ex = fit.exerciseById(id);
+ return ex == null ? '' : t.catalogName(ex.id, ex.name);
+}
+
+Future<void> showWorkoutNotesSheet(BuildContext context, String exerciseId) => showAppSheet<void>(
+ context: context,
+ isScrollControlled: true,
+ backgroundColor: Colors.transparent,
+ builder: (sheet) => AnimatedBuilder(
+ animation: fit,
+ builder: (sheet, _) {
+ final gc = sheet.gc;
+ final notes = fit.workoutNotesFor(exerciseId);
+ return _sheetBox(sheet, [
+ SheetTitle(t.workoutNotesTitle, subtitle: _exerciseTitle(exerciseId)),
+ const SizedBox(height: 16),
+ for (final n in notes) ...[
+ Container(
+ padding: const EdgeInsets.fromLTRB(14, 12, 8, 12),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(18)),
+ child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Expanded(
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Row(children: [
+ Icon(_iconOf(n), size: 12, color: gc.accent),
+ const SizedBox(width: 6),
+ Flexible(
+ child: Text(
+ n.pinned
+ ? t.workoutNoteEvery
+ : DateUtils.isSameDay(n.date, DateTime.now())
+ ? t.workoutNoteNext
+ : t.workoutNoteFromLast(t.shortDate(n.date)),
+ style: AppTheme.f(11, weight: FontWeight.w700, color: gc.accent, letterSpacing: 0.3)),
+ ),
+ ]),
+ const SizedBox(height: 6),
+ Text(n.text.trim(), style: AppTheme.f(14.5, weight: FontWeight.w500, color: gc.text, height: 1.4)),
+ ]),
+ ),
+ RoundAction(
+ label: t.editNote,
+ onTap: () => showWorkoutNoteEditor(sheet, exerciseId, note: n),
+ child: Icon(PhosphorIconsRegular.pencilSimple, size: 15, color: gc.textSecondary),
+ ),
+ ]),
+ ),
+ const SizedBox(height: 10),
+ ],
+ const SizedBox(height: 4),
+ GhostButton(
+ label: t.newNote,
+ icon: PhosphorIconsRegular.plus,
+ onTap: () => showWorkoutNoteEditor(sheet, exerciseId),
+ ),
+ ]);
+ },
+ ),
+ );
+
+Future<void> showWorkoutNoteEditor(BuildContext context, String exerciseId, {GymNote? note}) =>
+ showAppSheet<void>(
+ context: context,
+ isScrollControlled: true,
+ backgroundColor: Colors.transparent,
+ builder: (_) => _WorkoutNoteEditor(exerciseId: exerciseId, note: note),
+ );
+
+class _WorkoutNoteEditor extends StatefulWidget {
+ const _WorkoutNoteEditor({required this.exerciseId, this.note});
+
+ final String exerciseId;
+ final GymNote? note;
+
+ @override
+ State<_WorkoutNoteEditor> createState() => _WorkoutNoteEditorState();
+}
+
+class _WorkoutNoteEditorState extends State<_WorkoutNoteEditor> {
+ late final _text = TextEditingController(text: widget.note?.text ?? '');
+ late bool _every = widget.note == null || widget.note!.pinned || widget.note!.kind != NoteKind.plan;
+
+ @override
+ void dispose() {
+ _text.dispose();
+ super.dispose();
+ }
+
+ void _save() {
+ if (_text.text.trim().isEmpty) {
+ HapticFeedback.heavyImpact();
+ return;
+ }
+ final old = widget.note;
+ fit.saveNote(
+ id: old?.id,
+ exerciseId: widget.exerciseId,
+ date: old?.date ?? DateTime.now(),
+ kind: _every ? (old?.kind == NoteKind.plan ? NoteKind.note : old?.kind ?? NoteKind.note) : NoteKind.plan,
+ text: _text.text,
+ media: old?.media ?? const [],
+ pinned: _every,
+ );
+ HapticFeedback.lightImpact();
+ Navigator.of(context).pop();
+ }
+
+ Future<void> _delete() async {
+ final note = widget.note;
+ if (note == null) return;
+ final ok = await askConfirm(
+ context,
+ title: t.deleteNoteTitle,
+ body: t.deleteNoteBody,
+ confirmLabel: t.delete,
+ danger: true,
+ );
+ if (!ok || !mounted) return;
+ fit.deleteNote(note.id);
+ Navigator.of(context).pop();
+ }
+
+ Widget _choice(GymColors gc, bool every) {
+ final on = _every == every;
+ return Expanded(
+ child: Semantics(
+ selected: on,
+ button: true,
+ child: Pressable(
+ scale: 0.97,
+ onTap: () {
+ if (on) return;
+ HapticFeedback.selectionClick();
+ setState(() => _every = every);
+ },
+ child: AnimatedContainer(
+ duration: const Duration(milliseconds: 160),
+ padding: const EdgeInsets.fromLTRB(12, 11, 12, 12),
+ decoration: BoxDecoration(
+ color: on ? gc.accentSoft : gc.bgRaised2,
+ borderRadius: BorderRadius.circular(16),
+ border: Border.all(color: on ? gc.accent : gc.border, width: on ? 1.4 : 1),
+ ),
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Row(children: [
+ Icon(every ? PhosphorIconsFill.pushPin : PhosphorIconsFill.arrowBendDownRight,
+ size: 14, color: on ? gc.accent : gc.textTertiary),
+ const SizedBox(width: 6),
+ Flexible(
+ child: Text(every ? t.workoutNoteEvery : t.workoutNoteNext,
+ style: AppTheme.f(13, weight: FontWeight.w800, color: on ? gc.text : gc.textSecondary)),
+ ),
+ ]),
+ const SizedBox(height: 4),
+ Text(every ? t.workoutNoteEveryHint : t.workoutNoteNextHint,
+ style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textSecondary, height: 1.3)),
+ ]),
+ ),
+ ),
+ ),
+ );
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return _sheetBox(context, [
+ SheetTitle(widget.note == null ? t.newNote : t.editNote, subtitle: _exerciseTitle(widget.exerciseId)),
+ const SizedBox(height: 16),
+ Container(
+ padding: const EdgeInsets.fromLTRB(16, 4, 16, 4),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(16)),
+ child: TextField(
+ controller: _text,
+ autofocus: widget.note == null,
+ minLines: 2,
+ maxLines: 6,
+ maxLength: 1000,
+ textCapitalization: TextCapitalization.sentences,
+ cursorColor: gc.accent,
+ style: AppTheme.f(14.5, weight: FontWeight.w500, color: gc.text, height: 1.4),
+ decoration: InputDecoration(
+ border: InputBorder.none,
+ hintText: t.workoutNoteHint,
+ hintStyle: AppTheme.f(14.5, weight: FontWeight.w500, color: gc.textTertiary),
+ counterText: '',
+ ),
+ ),
+ ),
+ const SizedBox(height: 12),
+ IntrinsicHeight(
+ child: Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
+ _choice(gc, true),
+ const SizedBox(width: 8),
+ _choice(gc, false),
+ ]),
+ ),
+ const SizedBox(height: 18),
+ PrimaryButton(label: t.save, onTap: _save),
+ if (widget.note != null) ...[
+ const SizedBox(height: 6),
+ Center(
+ child: TextButton(
+ onPressed: _delete,
+ child: Text(t.delete, style: AppTheme.f(13, weight: FontWeight.w700, color: gc.danger)),
+ ),
+ ),
+ ],
+ ]);
+ }
+}