Skip to content

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

Lighter blur, text size and reduce motion

InlitXe4e6720c4d3c
diff --git a/lib/app/app_shell.dart b/lib/app/app_shell.dart
index a651782..849ddbc 100644
--- a/lib/app/app_shell.dart
+++ b/lib/app/app_shell.dart
@@ -3,6 +3,7 @@ import 'dart:math' as math;
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart' show RenderRepaintBoundary;
import 'package:flutter/services.dart';
import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';
@@ -92,7 +93,9 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Single
bool _collapsed = false;
int _restTick = fit.restDoneTick;
final _snap = SnapshotController();
- final _blurSnap = SnapshotController();
+ final _appKey = GlobalKey();
+ ui.Image? _blurred;
+ bool _blurQueued = false;
bool _changedUnder = false;
@override
@@ -205,8 +208,14 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Single
void _fitChanged() {
if (_snap.allowSnapshotting) _changedUnder = true;
_syncSnap();
+ if (_blurred != null) {
+ _blurAgain?.cancel();
+ _blurAgain = Timer(const Duration(milliseconds: 350), _queueBlur);
+ }
}
+ Timer? _blurAgain;
+
void _syncSnap() => scheduleMicrotask(() {
if (!mounted) return;
final on = fit.route == 'nutrition' && (glassOpen.value > 0 || (glassShown.value > 0 && !_changedUnder));
@@ -215,16 +224,49 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Single
_snap.allowSnapshotting = on;
});
- void _syncBlurSnap() => scheduleMicrotask(() {
- if (!mounted) return;
- final on = blurEffects && sheetRecede.value >= 0.999;
- if (on != _blurSnap.allowSnapshotting) _blurSnap.allowSnapshotting = on;
- });
+ void _syncBlurSnap() {
+ final p = sheetRecede.value;
+ if (p <= 0.001 || !blurEffects) {
+ if (_blurred != null) {
+ final old = _blurred;
+ _blurred = null;
+ WidgetsBinding.instance.addPostFrameCallback((_) => old?.dispose());
+ }
+ return;
+ }
+ if (_blurred == null) _queueBlur();
+ }
+
+ void _queueBlur() {
+ if (_blurQueued) return;
+ _blurQueued = true;
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ _blurQueued = false;
+ if (!mounted || sheetRecede.value <= 0.001 || !blurEffects) return;
+ final box = _appKey.currentContext?.findRenderObject();
+ if (box is! RenderRepaintBoundary || !box.hasSize) return;
+ const scale = 0.3;
+ final ratio = MediaQuery.devicePixelRatioOf(context) * scale;
+ try {
+ final small = box.toImageSync(pixelRatio: ratio);
+ final sigma = 2 * ratio;
+ final recorder = ui.PictureRecorder();
+ Canvas(recorder).drawImage(small, Offset.zero,
+ Paint()..imageFilter = ui.ImageFilter.blur(sigmaX: sigma, sigmaY: sigma, tileMode: TileMode.mirror));
+ final soft = recorder.endRecording().toImageSync(small.width, small.height);
+ small.dispose();
+ final old = _blurred;
+ setState(() => _blurred = soft);
+ old?.dispose();
+ } catch (_) {}
+ });
+ }
@override
void dispose() {
sheetRecede.removeListener(_syncBlurSnap);
- _blurSnap.dispose();
+ _blurAgain?.cancel();
+ _blurred?.dispose();
glassOpen.removeListener(_syncSnap);
glassShown.removeListener(_syncSnap);
fit.removeListener(_fitChanged);
@@ -313,6 +355,7 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Single
child: ValueListenableBuilder<double>(
valueListenable: sheetRecede,
child: RepaintBoundary(
+ key: _appKey,
child: BackdropGroup(
child: Stack(
children: [
@@ -407,22 +450,43 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Single
),
),
),
- builder: (context, p, app) => Transform.scale(
+ builder: (context, p, app) => Stack(fit: StackFit.expand, children: [
+ Transform.scale(
scale: 1 - 0.08 * p,
child: ClipRRect(
borderRadius: BorderRadius.circular(32 * p),
clipBehavior: p > 0.001 ? Clip.antiAlias : Clip.none,
- child: SnapshotWidget(
- controller: _blurSnap,
- mode: SnapshotMode.permissive,
- child: ImageFiltered(
- enabled: blurEffects && p > 0.01,
- imageFilter: ui.ImageFilter.blur(sigmaX: 2.5 * p, sigmaY: 2.5 * p),
- child: app,
- ),
- ),
+ child: Stack(children: [
+ app!,
+ if (_blurred != null && blurEffects && p > 0.01)
+ Positioned.fill(
+ child: IgnorePointer(child: CustomPaint(painter: _SoftCopy(_blurred!, p))),
+ ),
+ if (p > 0.01)
+ Positioned.fill(
+ child: IgnorePointer(
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(32 * p),
+ border: Border.all(color: Colors.white.withValues(alpha: 0.10 * p), width: 1.2),
+ ),
+ ),
+ ),
+ ),
+ ]),
),
),
+ if (p > 0.001)
+ IgnorePointer(
+ child: CustomPaint(
+ painter: _Corners(
+ scale: 1 - 0.08 * p,
+ radius: 32 * p,
+ color: fit.dark ? const Color(0xFF16161A) : const Color(0xFF3A3A3E),
+ ),
+ ),
+ ),
+ ]),
),
),
),
@@ -1051,3 +1115,51 @@ class _LiquidPillState extends State<_LiquidPill> with TickerProviderStateMixin
);
}
}
+
+class _Corners extends CustomPainter {
+ const _Corners({required this.scale, required this.radius, required this.color});
+
+ final double scale;
+ final double radius;
+ final Color color;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final page = Rect.fromCenter(
+ center: size.center(Offset.zero),
+ width: size.width * scale,
+ height: size.height * scale,
+ );
+ final r = radius * scale;
+ final path = Path()
+ ..fillType = PathFillType.evenOdd
+ ..addRect((Offset.zero & size).inflate(1))
+ ..addRRect(RRect.fromRectAndRadius(page.deflate(0.5), Radius.circular(r)));
+ canvas.drawPath(path, Paint()..color = color..isAntiAlias = true);
+ }
+
+ @override
+ bool shouldRepaint(_Corners old) => old.scale != scale || old.radius != radius || old.color != color;
+}
+
+class _SoftCopy extends CustomPainter {
+ const _SoftCopy(this.image, this.amount);
+
+ final ui.Image image;
+ final double amount;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ canvas.drawImageRect(
+ image,
+ Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble()),
+ Offset.zero & size,
+ Paint()
+ ..filterQuality = FilterQuality.medium
+ ..color = Color.fromRGBO(0, 0, 0, amount.clamp(0.0, 1.0)),
+ );
+ }
+
+ @override
+ bool shouldRepaint(_SoftCopy old) => old.image != image || old.amount != amount;
+}
diff --git a/lib/app/gymmane_app.dart b/lib/app/gymmane_app.dart
index 56a1b34..ef3cf84 100644
--- a/lib/app/gymmane_app.dart
+++ b/lib/app/gymmane_app.dart
@@ -17,7 +17,7 @@ class GymManeApp extends StatefulWidget {
}
class _GymManeAppState extends State<GymManeApp> {
- var _look = (fit.themeMode, fit.locale, fit.themePref == 'amoled');
+ var _look = (fit.themeMode, fit.locale, fit.themePref == 'amoled', fit.textSize, fit.calmMotion);
@override
void initState() {
@@ -32,7 +32,7 @@ class _GymManeAppState extends State<GymManeApp> {
}
void _watch() {
- final look = (fit.themeMode, fit.locale, fit.themePref == 'amoled');
+ final look = (fit.themeMode, fit.locale, fit.themePref == 'amoled', fit.textSize, fit.calmMotion);
if (look != _look) setState(() => _look = look);
}
@@ -52,10 +52,17 @@ class _GymManeAppState extends State<GymManeApp> {
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
- builder: (context, child) => MediaQuery.withClampedTextScaling(
- maxScaleFactor: GymManeApp.maxTextScale,
- child: _ButtonNavScrim(child: child!),
- ),
+ builder: (context, child) {
+ final media = MediaQuery.of(context);
+ final system = media.textScaler.clamp(maxScaleFactor: GymManeApp.maxTextScale).scale(100) / 100;
+ return MediaQuery(
+ data: media.copyWith(
+ textScaler: TextScaler.linear(system * fit.textFactor),
+ disableAnimations: media.disableAnimations || fit.calmMotion,
+ ),
+ child: _ButtonNavScrim(child: child!),
+ );
+ },
home: const AppShell(),
);
}
diff --git a/lib/main.dart b/lib/main.dart
index 840fbce..046920b 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -34,6 +34,7 @@ Future<void> main() async {
await RestAlarm.instance.init();
fit.loadFromStore();
fit.syncPhotoReminder();
+ fit.syncMeasureReminder();
fit.syncTrainReminder();
final watch = await DeviceKind.isWatch();
diff --git a/lib/state/fit_core.dart b/lib/state/fit_core.dart
index d27615b..d7f165c 100644
--- a/lib/state/fit_core.dart
+++ b/lib/state/fit_core.dart
@@ -36,6 +36,12 @@ int heatLevel(double v) {
abstract class FitCore extends ChangeNotifier {
Map<String, dynamic> toJson();
+ void healthSave(LoggedSession s) {}
+
+ void healthForget(LoggedSession s) {}
+
+ Future<void> stepsAllowed() async {}
+
String route = 'home';
final List<String> _routeStack = [];
final Map<String, bool> favorites = {};
@@ -66,6 +72,7 @@ abstract class FitCore extends ChangeNotifier {
final Map<String, String> exerciseUnits = {};
final Map<String, double> progressStep = {};
+ final Map<String, int> holdStep = {};
final Map<String, ProgressRule> progressRules = {};
@@ -96,6 +103,44 @@ abstract class FitCore extends ChangeNotifier {
final Map<String, Map<int, int>> videoMarks = {};
final Map<String, double> exerciseBar = {};
+ final Map<String, List<double>> weightStacks = {};
+
+ List<double>? stackFor(String id) {
+ final s = weightStacks[id];
+ return s == null || s.isEmpty ? null : s;
+ }
+
+ double snapToStack(String id, double kg, {int dir = 0}) {
+ final s = stackFor(id);
+ if (s == null) return kg;
+ if (dir > 0) {
+ for (final v in s) {
+ if (v > kg + 0.001) return v;
+ }
+ return s.last;
+ }
+ if (dir < 0) {
+ for (final v in s.reversed) {
+ if (v < kg - 0.001) return v;
+ }
+ return s.first;
+ }
+ var best = s.first;
+ for (final v in s) {
+ if ((v - kg).abs() < (best - kg).abs()) best = v;
+ }
+ return best;
+ }
+
+ double floorToStack(String id, double kg) {
+ final s = stackFor(id);
+ if (s == null) return kg;
+ var out = s.first;
+ for (final v in s) {
+ if (v <= kg + 0.001) out = v;
+ }
+ return out;
+ }
final Map<String, String> modeOverride = {};
@@ -130,6 +175,8 @@ abstract class FitCore extends ChangeNotifier {
int _dataRev = 0;
final Map<Object, (Object?, Object?)> _memo = {};
+ bool countsForMuscles(String id) => true;
+
T _remember<T>(Object key, T Function() build, [Object? extra]) {
final stamp = (
_dataRev,
diff --git a/lib/state/fit_state.dart b/lib/state/fit_state.dart
index 3942315..8bf2a6a 100644
--- a/lib/state/fit_state.dart
+++ b/lib/state/fit_state.dart
@@ -15,6 +15,7 @@ import '../l10n/l10n.dart';
import '../models/exercise.dart';
import '../models/gym_pass.dart';
import '../models/live_session.dart';
+import '../models/circuit.dart';
import '../models/measure.dart';
import '../models/note.dart';
import '../models/nutrition.dart';
@@ -40,6 +41,7 @@ import '../services/train_reminder.dart';
import '../services/workout_import.dart';
part 'awards_state.dart';
+part 'circuit_state.dart';
part 'fit_core.dart';
part 'gym_pass_state.dart';
part 'health_state.dart';
@@ -49,6 +51,7 @@ part 'moments_state.dart';
part 'notes_state.dart';
part 'nutrition_state.dart';
part 'places_state.dart';
+part 'report_state.dart';
part 'routines_state.dart';
part 'settings_state.dart';
part 'stats_state.dart';
@@ -58,7 +61,7 @@ part 'tools_state.dart';
part 'workout_state.dart';
class FitState extends FitCore
- with ToolsState, LibraryState, SettingsState, NotesState, PlacesState, GymPassState, MeasuresState, MomentsState, TimelineState, StatsState, StepsState, HealthState, NutritionState, AwardsState, RoutinesState, WorkoutState {
+ with ToolsState, LibraryState, SettingsState, NotesState, PlacesState, GymPassState, MeasuresState, MomentsState, TimelineState, StatsState, StepsState, HealthState, CircuitState, NutritionState, ReportState, AwardsState, RoutinesState, WorkoutState {
void loadFromStore() {
final data = withMergedExercises(Store.instance.load());
_loading = true;
@@ -140,6 +143,7 @@ class FitState extends FitCore
loadNutrition((data['nutrition'] as Map?)?.cast<String, dynamic>());
loadSteps((data['steps'] as Map?)?.cast<String, dynamic>());
loadHealth((data['health'] as Map?)?.cast<String, dynamic>());
+ loadCircuits(data['circuits'] as List?);
_restoreLiveSession(data);
}
_stampMemberSince();
@@ -209,6 +213,11 @@ class FitState extends FitCore
..clear()
..addAll(((data['barKg'] as Map?) ?? const {})
.map((k, v) => MapEntry(k as String, (v as num).toDouble())));
+ weightStacks
+ ..clear()
+ ..addAll(((data['stacks'] as Map?) ?? const {}).map((k, v) => MapEntry(
+ k as String,
+ ([for (final x in (v as List)) if (x is num && x.isFinite && x > 0) x.toDouble()]..sort()).take(60).toList())));
videoMarks
..clear()
..addAll(((data['marks'] as Map?) ?? const {}).map((k, v) => MapEntry(
@@ -247,6 +256,11 @@ class FitState extends FitCore
autoAdvance = data['autoAdvance'] as bool? ?? true;
keepScreenOn = data['keepAwake'] as bool? ?? true;
blurOn = data['blur'] as bool? ?? true;
+ final size = data['textSize'];
+ textSize = SettingsState.textSizes.contains(size) ? size as String : 'normal';
+ calmMotion = data['calm'] as bool? ?? false;
+ showMiniBody = data['miniBody'] as bool? ?? true;
+ askCheckIn = data['checkIn'] as bool? ?? true;
blurEffects = blurOn;
lowEndAsked = data['lowEndAsked'] as bool? ?? false;
startCountdown = data['countdown'] as bool? ?? true;
@@ -264,6 +278,10 @@ class FitState extends FitCore
..clear()
..addAll(((data['progress'] as Map?) ?? const {})
.map((k, v) => MapEntry(k as String, (v as num).toDouble())));
+ holdStep
+ ..clear()
+ ..addAll(((data['holdStep'] as Map?) ?? const {})
+ .map((k, v) => MapEntry(k as String, (v as num).toInt().clamp(0, 60))));
progressRules
..clear()
..addAll(((data['progressRules'] as Map?) ?? const {}).map(
@@ -384,11 +402,13 @@ class FitState extends FitCore
}
void _loadMeasures(Map<String, dynamic> data) {
+ loadCustomMeasures(data);
+ final keys = allMeasureKeys.toSet();
measures
..clear()
..addAll(((data['measures'] as List?) ?? const [])
.map((e) => BodyMeasure.fromJson((e as Map).cast<String, dynamic>()))
- .where((m) => kMeasureKeys.contains(m.key)));
+ .where((m) => keys.contains(m.key)));
}
void _loadPlaces(Map<String, dynamic> data) {
@@ -462,6 +482,10 @@ class FitState extends FitCore
'autoAdvance': autoAdvance,
'keepAwake': keepScreenOn,
if (!blurOn) 'blur': false,
+ if (textSize != 'normal') 'textSize': textSize,
+ if (calmMotion) 'calm': true,
+ if (!showMiniBody) 'miniBody': false,
+ if (!askCheckIn) 'checkIn': false,
if (lowEndAsked) 'lowEndAsked': true,
'countdown': startCountdown,
'gamify': gamification,
@@ -482,6 +506,7 @@ class FitState extends FitCore
'levelShown': Map.of(levelShown),
'goals': exerciseGoals.map((k, g) => MapEntry(k, {'t': g.target, if (g.due != null) 'd': g.due!.millisecondsSinceEpoch})),
'barKg': exerciseBar,
+ if (weightStacks.isNotEmpty) 'stacks': weightStacks,
if (plateBar != null) 'plateBar': plateBar,
'marks': videoMarks.map((k, v) => MapEntry(k, v.map((i, ms) => MapEntry('$i', ms)))),
'exMode': modeOverride,
@@ -514,6 +539,7 @@ class FitState extends FitCore
'exRest': exerciseRest,
if (exerciseUnits.isNotEmpty) 'exUnits': exerciseUnits,
'progress': progressStep,
+ if (holdStep.isNotEmpty) 'holdStep': holdStep,
if (progressRules.isNotEmpty)
'progressRules': progressRules.map((k, v) => MapEntry(k, v.toJson())),
'warmup': autoWarmup.toList(),
@@ -526,6 +552,7 @@ class FitState extends FitCore
'sessions': _stored('sessions', sessions, (s) => s.toJson(), parts: _sessionParts),
'bodyweight': bodyweight.map((b) => b.toJson()).toList(),
'measures': measures.map((m) => m.toJson()).toList(),
+ ...customMeasuresJson(),
'shots': shots.map((s) => s.toJson()).toList(),
'awards': awards.map((k, v) => MapEntry(k, v.toIso8601String())),
'awardsSeen': awardsSeen.toList(),
@@ -535,6 +562,7 @@ class FitState extends FitCore
'nutrition': nutritionJson(),
'steps': stepsJson(),
'health': healthJson(),
+ if (circuits.isNotEmpty) 'circuits': circuitsJson(),
if (session != null && !session!.complete) ...{
'live': session!.toJson(),
'liveStart': _runningSince?.toIso8601String(),
@@ -551,6 +579,24 @@ class FitState extends FitCore
for (final e in s.exercises) ...[e, e.incline, e.kcal, e.sets.length, ...e.sets],
];
+ void clearWorkouts() {
+ sessions.clear();
+ _filed = null;
+ awards.clear();
+ awardsSeen.clear();
+ pendingAwards.clear();
+ levelStay.clear();
+ levelSeen.clear();
+ levelShown.clear();
+ strengthExerciseId = null;
+ _memo.clear();
+ persistNow();
+ _refreshWidgets();
+ syncTrainReminder();
+ refreshAwards(silent: true);
+ notifyListeners();
+ }
+
void resetAllData() {
_saveDebounce?.cancel();
_sessionTimer?.cancel();
@@ -564,6 +610,9 @@ class FitState extends FitCore
sessions.clear();
bodyweight.clear();
measures.clear();
+ customMeasures.clear();
+ measureEveryDays = 0;
+ ProgressReminder.instance.cancelMeasure();
shots.clear();
compareFromId = null;
compareToId = null;
@@ -572,6 +621,7 @@ class FitState extends FitCore
loadNutrition(null);
loadSteps(null);
loadHealth(null);
+ circuits.clear();
healthGranted = {};
awards.clear();
awardsSeen.clear();
@@ -603,6 +653,7 @@ class FitState extends FitCore
exerciseRest.clear();
exerciseUnits.clear();
progressStep.clear();
+ holdStep.clear();
progressRules.clear();
autoWarmup.clear();
noSuggest.clear();
@@ -613,6 +664,7 @@ class FitState extends FitCore
exerciseGoals.clear();
videoMarks.clear();
exerciseBar.clear();
+ weightStacks.clear();
plateBar = null;
modeOverride.clear();
secondaryOverride.clear();
@@ -628,6 +680,8 @@ class FitState extends FitCore
profile = Profile();
showFocus = true;
showRecommended = true;
+ textSize = 'normal';
+ calmMotion = false;
showWeekStats = true;
showRoutineRow = true;
levelHints = true;
@@ -677,7 +731,8 @@ class FitState extends FitCore
Map<String, String>? restoredNoteMedia,
Map<String, String>? restoredShots,
Map<String, String>? restoredMoments,
- Map<String, String>? restoredFoods}) {
+ Map<String, String>? restoredFoods,
+ Map<String, String>? restoredPasses}) {
final before = jsonDecode(jsonEncode(Store.finite(toJson()))) as Map<String, dynamic>;
try {
applyBackup(backup,
@@ -685,7 +740,8 @@ class FitState extends FitCore
restoredNoteMedia: restoredNoteMedia,
restoredShots: restoredShots,
restoredMoments: restoredMoments,
- restoredFoods: restoredFoods);
+ restoredFoods: restoredFoods,
+ restoredPasses: restoredPasses);
return true;
} catch (e) {
debugPrint('applyBackup failed: $e');
@@ -699,7 +755,8 @@ class FitState extends FitCore
Map<String, String>? restoredNoteMedia,
Map<String, String>? restoredShots,
Map<String, String>? restoredMoments,
- Map<String, String>? restoredFoods}) {
+ Map<String, String>? restoredFoods,
+ Map<String, String>? restoredPasses}) {
final map = withMergedExercises(backup);
if (restoredMedia != null) restoredMedia = withMergedExercises(restoredMedia).cast<String, String>();
_loading = true;
@@ -717,7 +774,7 @@ class FitState extends FitCore
..clear()
..addAll(((map['favorites'] as Map?) ?? {}).map((k, v) => MapEntry(k as String, v as bool)));
_loadPlaces(map);
- _loadGymPasses(map);
+ _loadGymPasses(map, restored: restoredPasses);
_loadNotes(map);
if (restoredNoteMedia != null) _remapNoteMedia(restoredNoteMedia);
checkins
@@ -757,11 +814,13 @@ class FitState extends FitCore
loadNutrition((map['nutrition'] as Map?)?.cast<String, dynamic>(), restored: restoredFoods);
loadSteps((map['steps'] as Map?)?.cast<String, dynamic>());
loadHealth((map['health'] as Map?)?.cast<String, dynamic>());
+ loadCircuits(map['circuits'] as List?);
_seedCalculatorsFromProfile();
_loading = false;
_persist();
syncTrainReminder();
syncPhotoReminder();
+ syncMeasureReminder();
_refreshWidgets();
notifyListeners();
}
@@ -1153,7 +1212,7 @@ class FitState extends FitCore
final primary =
match?.primary ?? (kFilterMuscles.contains(hint) ? hint : guessMuscle(pe.name) ?? 'other');
exs.add(LoggedExercise(id, match?.name ?? pe.name, primary,
- [for (final s in pe.sets) LoggedSet(s.reps, s.weightKg, rpe: s.rpe)]));
+ [for (final s in pe.sets) LoggedSet(s.reps, s.weightKg, rpe: s.rpe, note: s.note, sec: s.sec, km: s.km)]));
}
if (exs.isEmpty) continue;
final ls = LoggedSession(ps.date, ps.durationSec, exs);
diff --git a/lib/state/library_state.dart b/lib/state/library_state.dart
index 1124b18..bfe2847 100644
--- a/lib/state/library_state.dart
+++ b/lib/state/library_state.dart
@@ -75,12 +75,30 @@ mixin LibraryState on FitCore {
return null;
}
+ final List<String> _exerciseTrail = [];
+
void openExercise(String id) {
+ final from = activeExerciseId;
+ if (route == 'exercise-detail' && from != null && from != id) {
+ _exerciseTrail.add(from);
+ } else if (route != 'exercise-detail') {
+ _exerciseTrail.clear();
+ }
activeExerciseId = id;
pushRoute('exercise-detail');
}
- void closeExerciseDetail() => popRoute(fallback: 'exercises');
+ void closeExerciseDetail() {
+ while (route == 'exercise-detail' && _exerciseTrail.isNotEmpty) {
+ final id = _exerciseTrail.removeLast();
+ if (id == activeExerciseId || exerciseById(id) == null) continue;
+ activeExerciseId = id;
+ notifyListeners();
+ return;
+ }
+ _exerciseTrail.clear();
+ popRoute(fallback: 'exercises');
+ }
void toggleFavorite(String id) {
favorites[id] = !(favorites[id] ?? false);
diff --git a/lib/state/routines_state.dart b/lib/state/routines_state.dart
index 9d0f0b4..fc46ff8 100644
--- a/lib/state/routines_state.dart
+++ b/lib/state/routines_state.dart
@@ -93,6 +93,19 @@ mixin RoutinesState on FitCore, LibraryState {
Routine? get activeRoutine => activeRoutineId == null ? null : _routine(activeRoutineId!);
+ Map<String, double> routineMuscleSets(Routine r) {
+ final out = <String, double>{};
+ for (final ex in routineExercises(r)) {
+ if (!countsForMuscles(ex.id)) continue;
+ final n = routineSets(r, ex.id).toDouble();
+ out[ex.primary] = (out[ex.primary] ?? 0) + n;
+ for (final m in ex.secondary) {
+ out[m] = (out[m] ?? 0) + n / 2;
+ }
+ }
+ return out;
+ }
+
List<Exercise> routineExercises(Routine r) {
final out = <Exercise>[];
for (final id in r.exerciseIds) {
diff --git a/lib/state/settings_state.dart b/lib/state/settings_state.dart
index cb9b14a..21ff190 100644
--- a/lib/state/settings_state.dart
+++ b/lib/state/settings_state.dart
@@ -42,6 +42,22 @@ mixin SettingsState on FitCore, ToolsState, LibraryState {
bool autoAdvance = true;
bool keepScreenOn = true;
bool blurOn = true;
+ String textSize = 'normal';
+ bool calmMotion = false;
+ bool showMiniBody = true;
+ bool askCheckIn = true;
+
+ void toggleMiniBody() {
+ showMiniBody = !showMiniBody;
+ _persist();
+ notifyListeners();
+ }
+
+ void toggleAskCheckIn() {
+ askCheckIn = !askCheckIn;
+ _persist();
+ notifyListeners();
+ }
bool lowEndAsked = false;
bool startCountdown = true;
bool gamification = true;
@@ -373,6 +389,27 @@ mixin SettingsState on FitCore, ToolsState, LibraryState {
notifyListeners();
}
+ static const textSizes = ['small', 'normal', 'large'];
+
+ double get textFactor => switch (textSize) {
+ 'small' => 0.9,
+ 'large' => 1.12,
+ _ => 1.0,
+ };
+
+ void setTextSize(String size) {
+ if (!textSizes.contains(size) || size == textSize) return;
+ textSize = size;
+ _persist();
+ notifyListeners();
+ }
+
+ void setCalmMotion(bool on) {
+ calmMotion = on;
+ _persist();
+ notifyListeners();
+ }
+
void setBlur(bool on) {
blurOn = on;
blurEffects = on;
@@ -387,6 +424,34 @@ mixin SettingsState on FitCore, ToolsState, LibraryState {
double? progressFor(String exerciseId) => progressStep[exerciseId];
+ void setWeightStack(String id, List<double> kg) {
+ final clean = <double>{for (final v in kg) if (v.isFinite && v > 0 && v < 1000) (v * 1000).round() / 1000}.toList()
+ ..sort();
+ if (clean.isEmpty) {
+ weightStacks.remove(id);
+ } else {
+ weightStacks[id] = clean.take(60).toList();
+ }
+ _persist();
+ notifyListeners();
+ }
+
+ static const holdSteps = [0, 5, 10, 15];
+
+ int holdStepFor(String exerciseId) => holdStep[exerciseId] ?? 0;
+
+ void cycleHoldStep(String exerciseId, int dir) {
+ final i = holdSteps.indexOf(holdStepFor(exerciseId));
+ final next = holdSteps[((i < 0 ? 0 : i) + dir).clamp(0, holdSteps.length - 1)];
+ if (next == 0) {
+ holdStep.remove(exerciseId);
+ } else {
+ holdStep[exerciseId] = next;
+ }
+ _persist();
+ notifyListeners();
+ }
+
bool hasProgress(String exerciseId) =>
(progressStep[exerciseId] ?? 0) > 0 && progressRule(exerciseId).kind != ProgressKind.manual;
diff --git a/lib/widgets/entrance.dart b/lib/widgets/entrance.dart
index d443d62..6993f05 100644
--- a/lib/widgets/entrance.dart
+++ b/lib/widgets/entrance.dart
@@ -95,19 +95,20 @@ class _RiseState extends State<Rise> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
if (_animate != true) return widget.child;
- return AnimatedBuilder(
- animation: _v,
- child: widget.child,
- builder: (context, child) {
- final v = _v.value;
- return Opacity(
- opacity: v,
- child: Transform.translate(
- offset: Offset(0, 22 * (1 - v)),
- child: Transform.scale(scale: 0.97 + 0.03 * v, child: child),
- ),
- );
- },
+ return FadeTransition(
+ opacity: _v,
+ child: AnimatedBuilder(
+ animation: _v,
+ child: RepaintBoundary(child: widget.child),
+ builder: (context, child) {
+ final v = _v.value;
+ return Transform(
+ transform: Matrix4.translationValues(0, 22 * (1 - v), 0)..scaleByDouble(0.97 + 0.03 * v, 0.97 + 0.03 * v, 1, 1),
+ alignment: Alignment.center,
+ child: child,
+ );
+ },
+ ),
);
}
}
diff --git a/lib/widgets/glass.dart b/lib/widgets/glass.dart
index 59e747e..bc58baa 100644
--- a/lib/widgets/glass.dart
+++ b/lib/widgets/glass.dart
@@ -243,10 +243,7 @@ class _EdgeBlurState extends State<EdgeBlur> {
}
_filtersFor = key;
- return _filters = [
- layer(widget.sigma * 0.35, 0.2, 1),
- layer(widget.sigma, 0.08, 0.66),
- ];
+ return _filters = [layer(widget.sigma * 0.8, 0.06, 0.82)];
}
@override
diff --git a/lib/widgets/scroll_away.dart b/lib/widgets/scroll_away.dart
new file mode 100644
index 0000000..ed7befd
--- /dev/null
+++ b/lib/widgets/scroll_away.dart
@@ -0,0 +1,98 @@
+import 'package:flutter/material.dart';
+
+double _smooth(double from, double to, double x) {
+ final t = ((x - from) / (to - from)).clamp(0.0, 1.0);
+ return t * t * (3 - 2 * t);
+}
+
+class ScrollAway extends StatefulWidget {
+ const ScrollAway({
+ super.key,
+ required this.child,
+ this.radius = 0,
+ this.depth = 0.08,
+ this.follow = 0.18,
+ this.dim = 0.45,
+ this.lead = 64,
+ });
+
+ final Widget child;
+ final double radius;
+ final double depth;
+ final double follow;
+ final double dim;
+ final double lead;
+
+ @override
+ State<ScrollAway> createState() => ScrollAwayState();
+}
+
+class ScrollAwayState extends State<ScrollAway> {
+ final progress = ValueNotifier<double>(0);
+ ScrollPosition? _pos;
+ double _height = 0;
+
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+ final pos = Scrollable.maybeOf(context)?.position;
+ if (pos == _pos) return;
+ _pos?.removeListener(_update);
+ _pos = pos?..addListener(_update);
+ WidgetsBinding.instance.addPostFrameCallback((_) => _update());
+ }
+
+ void _update() {
+ if (!mounted) return;
+ final pos = _pos;
+ final box = context.findRenderObject();
+ final view = Scrollable.maybeOf(context)?.context.findRenderObject();
+ if (pos == null || box is! RenderBox || view is! RenderBox) return;
+ if (!box.attached || !box.hasSize || !pos.hasPixels) return;
+ final top = box.localToGlobal(Offset.zero, ancestor: view).dy + pos.pixels;
+ _height = box.size.height;
+ final start = (top - widget.lead).clamp(0.0, double.infinity);
+ final span = top + _height - start;
+ final p = span <= 0 ? 0.0 : ((pos.pixels - start) / span).clamp(0.0, 1.0);
+ progress.value = (p * 200).roundToDouble() / 200;
+ }
+
+ @override
+ void dispose() {
+ _pos?.removeListener(_update);
+ progress.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ if (MediaQuery.disableAnimationsOf(context)) return widget.child;
+ final card = RepaintBoundary(child: widget.child);
+ return ValueListenableBuilder<double>(
+ valueListenable: progress,
+ child: card,
+ builder: (context, p, child) {
+ final scale = 1 - widget.depth * p;
+ return Transform(
+ alignment: const Alignment(0, -0.3),
+ transform: Matrix4.identity()
+ ..translateByDouble(0, p * widget.follow * _height, 0, 1)
+ ..scaleByDouble(scale, scale, 1, 1),
+ child: Opacity(
+ opacity: 1 - _smooth(0.2, 0.95, p),
+ child: widget.dim <= 0
+ ? child
+ : DecoratedBox(
+ position: DecorationPosition.foreground,
+ decoration: BoxDecoration(
+ color: Colors.black.withValues(alpha: widget.dim * p),
+ borderRadius: BorderRadius.circular(widget.radius),
+ ),
+ child: child,
+ ),
+ ),
+ );
+ },
+ );
+ }
+}
diff --git a/lib/widgets/sheet_page.dart b/lib/widgets/sheet_page.dart
index 427d3e2..ecca84f 100644
--- a/lib/widgets/sheet_page.dart
+++ b/lib/widgets/sheet_page.dart
@@ -14,7 +14,8 @@ class SheetPage extends StatefulWidget {
super.key,
required this.title,
required this.onBack,
- required this.children,
+ this.children = const [],
+ this.slivers,
this.eyebrow,
this.actions = const [],
});
@@ -24,6 +25,7 @@ class SheetPage extends StatefulWidget {
final List<Widget> actions;
final VoidCallback onBack;
final List<Widget> children;
+ final List<Widget>? slivers;
@override
State<SheetPage> createState() => _SheetPageState();
@@ -120,6 +122,46 @@ class _SheetPageState extends State<SheetPage> {
),
),
),
+ if (widget.slivers case final slivers?)
+ CustomScrollView(
+ controller: _scroll,
+ slivers: [
+ SliverToBoxAdapter(child: SizedBox(height: header)),
+ AnimatedBuilder(
+ animation: _scroll,
+ builder: (context, child) {
+ final d = ((_y - dockFrom) / 18).clamp(0.0, 1.0);
+ return DecoratedSliver(
+ decoration: BoxDecoration(
+ color: sheet,
+ borderRadius: BorderRadius.vertical(top: Radius.circular(_corner * (1 - d))),
+ border: Border.all(color: gc.text.withValues(alpha: 0.06 * (1 - d))),
+ ),
+ sliver: SliverMainAxisGroup(slivers: [
+ SliverToBoxAdapter(
+ child: Opacity(
+ opacity: 1 - d,
+ child: SheetHandle(
+ color: gc.text.withValues(alpha: 0.14),
+ margin: const EdgeInsets.only(top: 10),
+ ),
+ ),
+ ),
+ child!,
+ ]),
+ );
+ },
+ child: SliverMainAxisGroup(slivers: [
+ SliverPadding(
+ padding: EdgeInsets.fromLTRB(_side, 20, _side, pad.bottom + 40),
+ sliver: SliverMainAxisGroup(slivers: slivers),
+ ),
+ const SliverFillRemaining(hasScrollBody: false, child: SizedBox.shrink()),
+ ]),
+ ),
+ ],
+ )
+ else
SingleChildScrollView(
controller: _scroll,
child: Column(
@@ -155,9 +197,11 @@ class _SheetPageState extends State<SheetPage> {
),
);
},
- child: Padding(
- padding: EdgeInsets.fromLTRB(_side, 20, _side, pad.bottom + 40),
- child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: widget.children),
+ child: RepaintBoundary(
+ child: Padding(
+ padding: EdgeInsets.fromLTRB(_side, 20, _side, pad.bottom + 40),
+ child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: widget.children),
+ ),
),
),
],
diff --git a/lib/widgets/ui_kit.dart b/lib/widgets/ui_kit.dart
index b31a3d2..e3f2a95 100644
--- a/lib/widgets/ui_kit.dart
+++ b/lib/widgets/ui_kit.dart
@@ -9,12 +9,107 @@ import '../theme/app_theme.dart';
import 'rolling_text.dart';
import 'svg_icon.dart';
+const kSheetRadius = 28.0;
+
+BoxDecoration sheetDecoration(GymColors gc) => BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border.withValues(alpha: 0.6)),
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(kSheetRadius)),
+ );
+
+ShapeBorder sheetShape(GymColors gc) => RoundedRectangleBorder(
+ side: BorderSide(color: gc.border.withValues(alpha: 0.6)),
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(kSheetRadius)),
+ );
+
+class AppSheet extends StatelessWidget {
+ const AppSheet({super.key, required this.children, this.maxHeight = 0.88, this.bottom = 28, this.scroll = true});
+
+ final List<Widget> children;
+ final double maxHeight;
+ final double bottom;
+ final bool scroll;
+
+ @override
+ Widget build(BuildContext context) {
+ final media = MediaQuery.of(context);
+ final column = Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [const SheetHandle(), const SizedBox(height: 16), ...children],
+ );
+ return Padding(
+ padding: EdgeInsets.only(bottom: media.viewInsets.bottom),
+ child: Container(
+ constraints: BoxConstraints(maxHeight: media.size.height * maxHeight),
+ padding: sheetPad(context, bottom: bottom),
+ decoration: sheetDecoration(context.gc),
+ child: scroll ? SingleChildScrollView(child: column) : column,
+ ),
+ );
+ }
+}
+
+class FloatingActions extends StatelessWidget {
+ const FloatingActions({super.key, required this.child, required this.actions, this.fade = 56});
+
+ final Widget child;
+ final Widget actions;
+ final double fade;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Stack(children: [
+ child,
+ Positioned(
+ left: 0,
+ right: 0,
+ bottom: 0,
+ child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [
+ IgnorePointer(
+ child: Container(
+ height: fade,
+ decoration: BoxDecoration(
+ gradient: LinearGradient(
+ begin: Alignment.topCenter,
+ end: Alignment.bottomCenter,
+ colors: [gc.bgRaised.withValues(alpha: 0), gc.bgRaised.withValues(alpha: 0.92)],
+ ),
+ ),
+ ),
+ ),
+ ColoredBox(color: gc.bgRaised.withValues(alpha: 0.92), child: actions),
+ ]),
+ ),
+ ]);
+ }
+}
+
+class SectionLabel extends StatelessWidget {
+ const SectionLabel(this.text, {super.key, this.color});
+
+ final String text;
+ final Color? color;
+
+ @override
+ Widget build(BuildContext context) => Text(
+ text.toUpperCase(),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: kickerStyle(context.gc, color: color),
+ );
+}
+
+TextStyle kickerStyle(GymColors gc, {Color? color}) =>
+ AppTheme.f(10.5, weight: FontWeight.w700, color: color ?? gc.textTertiary, letterSpacing: 1.4);
+
class SoftCard extends StatelessWidget {
const SoftCard({
super.key,
required this.child,
this.padding = const EdgeInsets.all(20),
- this.radius = 20,
+ this.radius = 22,
this.borderColor,
this.color,
this.clip = false,
@@ -258,12 +353,12 @@ class SheetTitle extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- Text(text, textAlign: TextAlign.center, style: AppTheme.f(17, weight: FontWeight.w700, color: gc.text)),
+ Text(text, textAlign: TextAlign.center, style: AppTheme.f(19, weight: FontWeight.w800, color: gc.text, height: 1.2)),
if (subtitle != null) ...[
- const SizedBox(height: 4),
+ const SizedBox(height: 5),
Text(subtitle!,
textAlign: TextAlign.center,
- style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textSecondary, height: 1.35)),
+ style: AppTheme.f(13, weight: FontWeight.w500, color: gc.textSecondary, height: 1.35)),
],
],
);
@@ -761,7 +856,7 @@ class ToolRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SoftCard(
- radius: 20,
+ radius: 22,
borderColor: Colors.transparent,
padding: EdgeInsets.zero,
child: _line(context),
@@ -967,7 +1062,7 @@ class PrimaryButton extends StatelessWidget {
required this.onTap,
this.bg,
this.fg,
- this.height = 56,
+ this.height = 52,
this.icon,
});
final String label;
diff --git a/test/route_stack_test.dart b/test/route_stack_test.dart
index 46d2fe4..e9e66ae 100644
--- a/test/route_stack_test.dart
+++ b/test/route_stack_test.dart
@@ -22,6 +22,26 @@ void main() {
expect(fit.route, 'exercises');
});
+ test('a similar exercise opens on top and back returns to the first one', () {
+ final a = fit.allExercises[0].id;
+ final b = fit.allExercises[1].id;
+ final c = fit.allExercises[2].id;
+ fit.goExercises();
+ fit.openExercise(a);
+ fit.openExercise(b);
+ fit.openExercise(c);
+ expect(fit.activeExerciseId, c);
+ fit.handleBack();
+ expect((fit.route, fit.activeExerciseId), ('exercise-detail', b));
+ fit.handleBack();
+ expect((fit.route, fit.activeExerciseId), ('exercise-detail', a));
+ fit.handleBack();
+ expect(fit.route, 'exercises');
+ fit.openExercise(c);
+ fit.handleBack();
+ expect(fit.route, 'exercises');
+ });
+
test('writing a note inside an exercise does not lock you in', () {
fit.goExercises();
fit.openExercise(exId());
@@ -85,6 +105,7 @@ void main() {
fit.openExercise(exId());
fit.openExercise(fit.allExercises[1].id);
fit.handleBack();
+ fit.handleBack();
expect(fit.route, 'exercises');
});
diff --git a/test/settings_test.dart b/test/settings_test.dart
index 6a25ad0..afd9ad8 100644
--- a/test/settings_test.dart
+++ b/test/settings_test.dart
@@ -87,6 +87,27 @@ void main() {
});
});
+ group('tamaño del texto y animaciones', () {
+ setUp(() async {
+ SharedPreferences.setMockInitialValues({});
+ await Store.instance.init();
+ fit.resetAllData();
+ fit.onboarded = true;
+ });
+
+ test('se eligen, se recuerdan y lo raro no entra', () {
+ expect(fit.textFactor, 1.0);
+ fit.setTextSize('large');
+ fit.setTextSize('giant');
+ fit.setCalmMotion(true);
+ fit.persistNow();
+ fit.loadFromStore();
+ expect(fit.textSize, 'large');
+ expect(fit.textFactor, greaterThan(1));
+ expect(fit.calmMotion, isTrue);
+ });
+ });
+
group('#92 inicio de semana', () {
setUp(() async {
SharedPreferences.setMockInitialValues({});
diff --git a/test/shell_repaint_test.dart b/test/shell_repaint_test.dart
index d1741f1..962b03d 100644
--- a/test/shell_repaint_test.dart
+++ b/test/shell_repaint_test.dart
@@ -1,4 +1,6 @@
+import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
+import 'package:gymmane/widgets/glass.dart';
import 'package:gymmane/widgets/ui_kit.dart';
import 'package:gymmane/app/gymmane_app.dart';
import 'package:gymmane/l10n/l10n.dart';
@@ -62,4 +64,23 @@ void main() {
fit.measures.clear();
fit.persistNow();
});
+
+ testWidgets('al abrir una hoja el fondo se suaviza con una copia y al cerrarla se va', (tester) async {
+ blurEffects = true;
+ await open(tester, 'home');
+ final ctx = tester.element(find.byType(Scaffold).first);
+ bool soft() => tester
+ .widgetList<CustomPaint>(find.byType(CustomPaint))
+ .any((c) => c.painter.runtimeType.toString() == '_SoftCopy');
+ showAppSheet<void>(context: ctx, builder: (_) => const SizedBox(height: 200));
+ for (var i = 0; i < 20; i++) {
+ await tester.pump(const Duration(milliseconds: 40));
+ }
+ expect(sheetRecede.value, greaterThan(0.9));
+ expect(soft(), isTrue);
+ Navigator.of(ctx).pop();
+ await tester.pumpAndSettle();
+ expect(sheetRecede.value, 0);
+ expect(soft(), isFalse);
+ });
}