Skip to content

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

Add name and URL links to notes and raise the note limit to 3000

InlitXddaf1b7794cb
diff --git a/lib/models/note.dart b/lib/models/note.dart
index 8d21da1..03b9cec 100644
--- a/lib/models/note.dart
+++ b/lib/models/note.dart
@@ -1,5 +1,26 @@
enum NoteKind { note, plan, done, pain }
+class NoteLink {
+ const NoteLink({required this.name, required this.url});
+
+ final String name;
+ final String url;
+
+ Map<String, dynamic> toJson() => {'n': name, 'u': url};
+
+ factory NoteLink.fromJson(Map<String, dynamic> j) =>
+ NoteLink(name: (j['n'] ?? '') as String, url: (j['u'] ?? '') as String);
+
+ static Uri? parse(String raw) {
+ final text = raw.trim();
+ if (text.isEmpty || text.contains(RegExp(r'\s'))) return null;
+ final uri = Uri.tryParse(text.contains('://') ? text : 'https://$text');
+ if (uri == null || !uri.hasAuthority || uri.host.isEmpty) return null;
+ if (uri.scheme != 'http' && uri.scheme != 'https') return null;
+ return uri;
+ }
+}
+
class GymNote {
const GymNote({
required this.id,
@@ -11,6 +32,7 @@ class GymNote {
required this.createdAt,
this.pinned = false,
this.folder = '',
+ this.links = const [],
});
final String id;
@@ -22,6 +44,7 @@ class GymNote {
final DateTime createdAt;
final bool pinned;
final String folder;
+ final List<NoteLink> links;
bool get isGeneral => exerciseId.isEmpty;
@@ -40,6 +63,7 @@ class GymNote {
List<String>? media,
bool? pinned,
String? folder,
+ List<NoteLink>? links,
}) =>
GymNote(
id: id,
@@ -51,6 +75,7 @@ class GymNote {
createdAt: createdAt,
pinned: pinned ?? this.pinned,
folder: folder ?? this.folder,
+ links: links ?? this.links,
);
Map<String, dynamic> toJson() => {
@@ -63,6 +88,7 @@ class GymNote {
'c': createdAt.toIso8601String(),
if (pinned) 'p': true,
if (folder.isNotEmpty) 'f': folder,
+ if (links.isNotEmpty) 'l': [for (final l in links) l.toJson()],
};
factory GymNote.fromJson(Map<String, dynamic> j) {
@@ -77,6 +103,10 @@ class GymNote {
createdAt: created,
pinned: j['p'] == true,
folder: (j['f'] ?? '') as String,
+ links: [
+ for (final l in (j['l'] as List?) ?? const [])
+ if (l is Map) NoteLink.fromJson(l.cast<String, dynamic>()),
+ ],
);
}
}
diff --git a/lib/screens/note_edit_screen.dart b/lib/screens/note_edit_screen.dart
index c0d8c19..2caf28f 100644
--- a/lib/screens/note_edit_screen.dart
+++ b/lib/screens/note_edit_screen.dart
@@ -16,7 +16,7 @@ import '../widgets/note_folder.dart';
import '../widgets/note_kit.dart';
import '../widgets/ui_kit.dart';
-const int _kNoteMaxLength = 1000;
+const int _kNoteMaxLength = 3000;
class NoteEditScreen extends StatefulWidget {
const NoteEditScreen({super.key});
@@ -32,6 +32,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 final List<NoteLink> _links = [...?_note?.links];
late bool _pinned = _note?.pinned ?? false;
late String _folder = _note?.folder ?? fit.noteDraftFolder;
final List<String> _added = [];
@@ -60,6 +61,7 @@ class _NoteEditScreenState extends State<NoteEditScreen> {
media: _media,
pinned: _pinned,
folder: _folder,
+ links: _links,
);
fit.closeNoteEditor();
}
@@ -88,6 +90,18 @@ class _NoteEditScreenState extends State<NoteEditScreen> {
} catch (_) {}
}
+ Future<void> _editLink([int? index]) async {
+ final link = await askLink(context, initial: index == null ? null : _links[index]);
+ if (link == null || !mounted) return;
+ setState(() {
+ if (index == null) {
+ _links.add(link);
+ } else {
+ _links[index] = link;
+ }
+ });
+ }
+
Future<void> _confirmDelete() async {
final note = _note;
if (note == null) return;
@@ -225,6 +239,21 @@ class _NoteEditScreenState extends State<NoteEditScreen> {
const SizedBox(height: 22),
_label(gc, t.noteMediaLabel),
_mediaGrid(gc),
+ const SizedBox(height: 22),
+ _label(gc, t.noteLinksLabel),
+ for (int i = 0; i < _links.length; i++) ...[
+ NoteLinkTile(
+ link: _links[i],
+ onTap: () => _editLink(i),
+ onRemove: () => setState(() => _links.removeAt(i)),
+ ),
+ const SizedBox(height: 8),
+ ],
+ GhostButton(
+ label: t.noteLinkAdd,
+ icon: PhosphorIconsRegular.link,
+ onTap: _editLink,
+ ),
const SizedBox(height: 28),
PrimaryButton(
label: t.save,
diff --git a/lib/state/notes_state.dart b/lib/state/notes_state.dart
index 7aeb59e..17d60cf 100644
--- a/lib/state/notes_state.dart
+++ b/lib/state/notes_state.dart
@@ -170,6 +170,7 @@ mixin NotesState on FitCore, LibraryState {
List<String> media = const [],
bool? pinned,
String? folder,
+ List<NoteLink> links = const [],
}) {
final body = text.trim();
if (body.isEmpty) return;
@@ -187,6 +188,7 @@ mixin NotesState on FitCore, LibraryState {
createdAt: DateTime.now(),
pinned: (pinned ?? false) && exerciseId.isNotEmpty,
folder: folder ?? '',
+ links: [...links],
));
} else {
final old = notes[index];
@@ -201,6 +203,7 @@ mixin NotesState on FitCore, LibraryState {
media: [...media],
pinned: exerciseId.isEmpty ? false : pinned,
folder: folder,
+ links: [...links],
);
}
noteDay = day;
diff --git a/lib/widgets/dialogs.dart b/lib/widgets/dialogs.dart
index efdb9a0..54decd0 100644
--- a/lib/widgets/dialogs.dart
+++ b/lib/widgets/dialogs.dart
@@ -1,9 +1,13 @@
import 'package:flutter/material.dart';
+import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';
+import 'package:url_launcher/url_launcher.dart';
import '../l10n/l10n.dart';
+import '../models/note.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
import 'glass.dart';
+import 'liquid_notch.dart';
import 'ui_kit.dart';
AlertDialog appDialog(
@@ -142,3 +146,97 @@ Future<double?> askNumber(
return double.tryParse((raw ?? '').trim().replaceAll(',', '.'));
}
+
+Future<NoteLink?> askLink(BuildContext context, {NoteLink? initial}) async {
+ final gc = context.gc;
+ final name = TextEditingController(text: initial?.name ?? '');
+ final url = TextEditingController(text: initial?.url ?? '');
+ bool bad = false;
+ InputDecoration deco(String hint, {String? error}) => InputDecoration(
+ hintText: hint,
+ errorText: error,
+ hintStyle: AppTheme.s(15, color: gc.textTertiary),
+ errorStyle: AppTheme.s(12, color: gc.danger),
+ enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: gc.border)),
+ focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: gc.accent)),
+ errorBorder: UnderlineInputBorder(borderSide: BorderSide(color: gc.danger)),
+ focusedErrorBorder: UnderlineInputBorder(borderSide: BorderSide(color: gc.danger)),
+ );
+ final result = await showAppDialog<NoteLink>(
+ context: context,
+ builder: (dctx) => StatefulBuilder(
+ builder: (dctx, setState) {
+ void submit() {
+ final uri = NoteLink.parse(url.text);
+ if (uri == null) {
+ setState(() => bad = true);
+ return;
+ }
+ final label = name.text.trim();
+ Navigator.of(dctx).pop(NoteLink(
+ name: label.isEmpty ? uri.host.replaceFirst('www.', '') : label,
+ url: uri.toString(),
+ ));
+ }
+
+ return appDialog(
+ gc,
+ title: Text(initial == null ? t.noteLinkAdd : t.noteLinkEdit,
+ style: AppTheme.d(18, weight: FontWeight.w700, color: gc.text)),
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ TextField(
+ controller: name,
+ autofocus: true,
+ textCapitalization: TextCapitalization.sentences,
+ textInputAction: TextInputAction.next,
+ maxLength: 60,
+ style: AppTheme.s(15, color: gc.text),
+ cursorColor: gc.accent,
+ decoration: deco(t.noteLinkNameHint).copyWith(counterText: ''),
+ ),
+ const SizedBox(height: 8),
+ TextField(
+ controller: url,
+ keyboardType: TextInputType.url,
+ autocorrect: false,
+ style: AppTheme.s(15, color: gc.text),
+ cursorColor: gc.accent,
+ decoration: deco(t.noteLinkUrlHint, error: bad ? t.noteLinkInvalid : null),
+ onChanged: (_) {
+ if (bad) setState(() => bad = false);
+ },
+ onSubmitted: (_) => submit(),
+ ),
+ ],
+ ),
+ actions: [
+ dialogAction(t.cancel, gc.textSecondary, () => Navigator.of(dctx).pop(), strong: false),
+ dialogAction(t.save, gc.accent, submit),
+ ],
+ );
+ },
+ ),
+ );
+ Future<void>.delayed(const Duration(milliseconds: 600), () {
+ name.dispose();
+ url.dispose();
+ });
+ return result;
+}
+
+Future<void> openNoteLink(BuildContext context, NoteLink link) async {
+ final uri = NoteLink.parse(link.url);
+ var ok = false;
+ if (uri != null) {
+ try {
+ ok = await launchUrl(uri, mode: LaunchMode.externalApplication);
+ } catch (_) {
+ ok = false;
+ }
+ }
+ if (!ok && context.mounted) {
+ showNotchToast(context, t.cantOpenLink, icon: PhosphorIconsFill.warningCircle, accent: context.gc.danger);
+ }
+}
diff --git a/lib/widgets/note_kit.dart b/lib/widgets/note_kit.dart
index d2c597e..3d372d0 100644
--- a/lib/widgets/note_kit.dart
+++ b/lib/widgets/note_kit.dart
@@ -14,6 +14,7 @@ import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
import 'exercise_media.dart';
import 'exercise_preview.dart';
+import 'dialogs.dart';
import 'file_thumb.dart';
import 'glass.dart';
import 'note_folder.dart';
@@ -764,6 +765,13 @@ class _NoteSheetView extends StatelessWidget {
),
),
],
+ if (note.links.isNotEmpty) ...[
+ const SizedBox(height: 18),
+ for (final link in note.links) ...[
+ NoteLinkTile(link: link, onTap: () => openNoteLink(context, link)),
+ const SizedBox(height: 8),
+ ],
+ ],
if (note.media.isNotEmpty) ...[
const SizedBox(height: 18),
_AllPhotos(media: note.media, scope: 'sheet${note.id}'),
@@ -808,6 +816,63 @@ class _NoteSheetView extends StatelessWidget {
}
}
+class NoteLinkTile extends StatelessWidget {
+ const NoteLinkTile({super.key, required this.link, required this.onTap, this.onRemove});
+
+ final NoteLink link;
+ final VoidCallback onTap;
+ final VoidCallback? onRemove;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Pressable(
+ scale: 0.98,
+ onTap: onTap,
+ child: Container(
+ padding: const EdgeInsetsDirectional.fromSTEB(14, 10, 6, 10),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(16)),
+ child: Row(children: [
+ Icon(PhosphorIconsRegular.link, size: 18, color: gc.accent),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(link.name,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(14, weight: FontWeight.w700, color: gc.text, height: 1.25)),
+ const SizedBox(height: 2),
+ Text(link.url,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textTertiary)),
+ ]),
+ ),
+ const SizedBox(width: 6),
+ if (onRemove == null)
+ Padding(
+ padding: const EdgeInsetsDirectional.only(end: 8),
+ child: Icon(PhosphorIconsRegular.arrowUpRight, size: 15, color: gc.textTertiary),
+ )
+ else
+ Semantics(
+ button: true,
+ label: t.delete,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onRemove,
+ child: Padding(
+ padding: const EdgeInsets.all(12),
+ child: Icon(PhosphorIconsBold.x, size: 13, color: gc.textTertiary),
+ ),
+ ),
+ ),
+ ]),
+ ),
+ );
+ }
+}
+
class _AllPhotos extends StatelessWidget {
const _AllPhotos({required this.media, required this.scope});
diff --git a/test/exercise_notes_test.dart b/test/exercise_notes_test.dart
index f5c47ec..91c43e0 100644
--- a/test/exercise_notes_test.dart
+++ b/test/exercise_notes_test.dart
@@ -182,4 +182,25 @@ void main() {
expect(fit.notes, hasLength(2));
expect(fit.notes.every((n) => n.folder.isEmpty), isTrue);
});
+
+ test('note links survive JSON and reject bad addresses', () {
+ final note = GymNote(
+ id: 'n1',
+ exerciseId: '',
+ date: DateTime(2026, 11, 9),
+ kind: NoteKind.note,
+ text: 'Programa',
+ createdAt: DateTime(2026, 11, 9),
+ links: const [NoteLink(name: 'Vídeo', url: 'https://example.com/a?b=1')],
+ );
+ final back = GymNote.fromJson(note.toJson());
+ expect(back.links.single.name, 'Vídeo');
+ expect(back.links.single.url, 'https://example.com/a?b=1');
+ expect(GymNote.fromJson({...note.toJson()}..remove('l')).links, isEmpty);
+ expect(NoteLink.parse('example.com/x')?.toString(), 'https://example.com/x');
+ expect(NoteLink.parse('javascript:alert(1)'), isNull);
+ expect(NoteLink.parse('ftp://example.com'), isNull);
+ expect(NoteLink.parse('hola mundo'), isNull);
+ expect(NoteLink.parse(' '), isNull);
+ });
}