Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Save and switch weekly plans
InlitX95f7bc471879
diff --git a/lib/screens/routines_screen.dart b/lib/screens/routines_screen.dartindex 9437288..d5a7a3f 100644--- a/lib/screens/routines_screen.dart+++ b/lib/screens/routines_screen.dart@@ -86,6 +86,10 @@ class RoutinesScreen extends StatelessWidget {padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),child: Column(children: [for (int i = 0; i < 7; i++) _dayRow(context, gc, i)]),),+ if (!fit.rotation && fit.routines.isNotEmpty) ...[+ const SizedBox(height: 10),+ _plansRow(context, gc),+ ],const SizedBox(height: 26),Text(t.yourRoutines, style: AppTheme.f(12, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 1.5)),const SizedBox(height: 10),@@ -192,7 +196,123 @@ class RoutinesScreen extends StatelessWidget {);}- Widget _shareOption(GymColors gc, IconData icon, String title, String hint, VoidCallback onTap) {+ Widget _plansRow(BuildContext context, GymColors gc) {+ Widget chip(String label, bool active, VoidCallback onTap, {IconData? icon}) => GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: Container(+ padding: const EdgeInsets.symmetric(horizontal: 13, vertical: 8),+ decoration: BoxDecoration(+ color: active ? gc.ember : gc.bgRaised,+ borderRadius: BorderRadius.circular(20),+ border: Border.all(color: active ? gc.ember : gc.border),+ ),+ child: Row(mainAxisSize: MainAxisSize.min, children: [+ if (icon != null) ...[+ Icon(icon, size: 13, color: gc.textSecondary),+ const SizedBox(width: 5),+ ],+ Text(label,+ style: AppTheme.f(12.5,+ weight: FontWeight.w600, color: active ? gc.onEmber : (icon != null ? gc.textSecondary : gc.text))),+ ]),+ ),+ );++ return SingleChildScrollView(+ scrollDirection: Axis.horizontal,+ child: Row(children: [+ for (final p in fit.savedPlans) ...[+ chip(p.name, p.id == fit.currentPlanId, () {+ if (p.id == fit.currentPlanId) return _planMenu(context, p);+ HapticFeedback.selectionClick();+ fit.switchPlan(p.id);+ }),+ const SizedBox(width: 8),+ ],+ chip(t.planNew, false, () => _newPlanSheet(context), icon: PhosphorIconsBold.plus),+ ]),+ );+ }++ Future<void> _namePlan(BuildContext context, {required bool empty}) async {+ final name = await askText(context, title: t.planName, hint: t.planNameHint);+ if (name != null && name.trim().isNotEmpty) fit.savePlanAs(name, empty: empty);+ }++ void _newPlanSheet(BuildContext context) {+ final gc = context.gc;+ showAppSheet<void>(+ context: context,+ backgroundColor: Colors.transparent,+ builder: (sheet) => Container(+ padding: sheetPad(sheet),+ decoration: BoxDecoration(+ color: gc.bgRaised,+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),+ ),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ const SheetHandle(),+ const SizedBox(height: 16),+ SheetTitle(t.planNew, subtitle: t.plansHint),+ const SizedBox(height: 14),+ _shareOption(gc, PhosphorIconsRegular.floppyDisk, t.planSaveWeek, t.planSaveWeekHint, () {+ Navigator.pop(sheet);+ _namePlan(context, empty: false);+ }, trailing: PhosphorIconsRegular.caretRight),+ _shareOption(gc, PhosphorIconsRegular.calendarBlank, t.planEmptyWeek, t.planEmptyWeekHint, () {+ Navigator.pop(sheet);+ _namePlan(context, empty: true);+ }, trailing: PhosphorIconsRegular.caretRight),+ ],+ ),+ ),+ );+ }++ void _planMenu(BuildContext context, SavedPlan p) {+ final gc = context.gc;+ showAppSheet<void>(+ context: context,+ backgroundColor: Colors.transparent,+ builder: (sheet) => Container(+ padding: sheetPad(sheet),+ decoration: BoxDecoration(+ color: gc.bgRaised,+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),+ ),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ const SheetHandle(),+ const SizedBox(height: 16),+ SheetTitle(p.name, subtitle: t.plansHint),+ const SizedBox(height: 14),+ OptionGroup([+ OptionItem(t.planRename, icon: PhosphorIconsRegular.pencilSimple, onTap: () async {+ Navigator.pop(sheet);+ final name = await askText(context, title: t.planName, initial: p.name, hint: t.planNameHint);+ if (name != null) fit.renamePlan(p.id, name);+ }),+ OptionItem(t.planDelete, icon: PhosphorIconsRegular.trash, danger: true, onTap: () async {+ Navigator.pop(sheet);+ final ok = await askConfirm(context,+ title: t.planDelete, body: t.planDeleteBody, confirmLabel: t.delete, danger: true);+ if (ok) fit.deletePlan(p.id);+ }),+ ]),+ ],+ ),+ ),+ );+ }++ Widget _shareOption(GymColors gc, IconData icon, String title, String hint, VoidCallback onTap,+ {IconData trailing = PhosphorIconsRegular.shareNetwork}) {return GestureDetector(behavior: HitTestBehavior.opaque,onTap: onTap,@@ -224,7 +344,7 @@ class RoutinesScreen extends StatelessWidget {],),),- Icon(PhosphorIconsRegular.shareNetwork, size: 16, color: gc.textSecondary),+ Icon(trailing, size: 16, color: gc.textSecondary),]),),);diff --git a/lib/state/routines_state.dart b/lib/state/routines_state.dartindex cf26dd0..ef25b62 100644--- a/lib/state/routines_state.dart+++ b/lib/state/routines_state.dart@@ -5,6 +5,76 @@ const int kDefaultRoutineSets = 3;mixin RoutinesState on FitCore, LibraryState {String? activeRoutineId;int _routineSeq = 0;+ final List<SavedPlan> savedPlans = [];+ String currentPlanId = '';++ SavedPlan _snapshot(String id, String name) => SavedPlan(+ id,+ name,+ Map.of(weeklyPlan),+ {for (final e in planExtras.entries) e.key: List.of(e.value)},+ multi: multiPlan,+ );++ List<SavedPlan> get savedPlansLive => [+ for (final p in savedPlans) p.id == currentPlanId ? _snapshot(p.id, p.name) : p,+ ];++ void _storeCurrentPlan() {+ final i = savedPlans.indexWhere((p) => p.id == currentPlanId);+ if (i >= 0) savedPlans[i] = _snapshot(currentPlanId, savedPlans[i].name);+ }++ void savePlanAs(String name, {bool empty = false}) {+ final n = name.trim();+ if (n.isEmpty) return;+ _storeCurrentPlan();+ if (empty && currentPlanId.isEmpty && weeklyPlan.isNotEmpty) {+ final mine = 'p${DateTime.now().microsecondsSinceEpoch}-${_routineSeq++}';+ savedPlans.add(_snapshot(mine, t.planMine));+ }+ final id = 'p${DateTime.now().microsecondsSinceEpoch}-${_routineSeq++}';+ if (empty) {+ weeklyPlan.clear();+ planExtras.clear();+ }+ savedPlans.add(_snapshot(id, n));+ currentPlanId = id;+ _planChanged();+ }++ void switchPlan(String id) {+ if (id == currentPlanId) return;+ final i = savedPlans.indexWhere((p) => p.id == id);+ if (i < 0) return;+ _storeCurrentPlan();+ final p = savedPlans[i];+ weeklyPlan+ ..clear()+ ..addAll(p.week);+ planExtras+ ..clear()+ ..addAll({for (final e in p.extras.entries) e.key: List.of(e.value)});+ multiPlan = p.multi;+ currentPlanId = id;+ _planChanged();+ }++ void renamePlan(String id, String name) {+ final n = name.trim();+ final i = savedPlans.indexWhere((p) => p.id == id);+ if (i < 0 || n.isEmpty) return;+ savedPlans[i].name = n;+ _persist();+ notifyListeners();+ }++ void deletePlan(String id) {+ savedPlans.removeWhere((p) => p.id == id);+ if (currentPlanId == id) currentPlanId = '';+ _persist();+ notifyListeners();+ }void goRoutines() => pushRoute('routines');@@ -368,6 +438,9 @@ mixin RoutinesState on FitCore, LibraryState {weeklyPlan[day] = extras.removeAt(0);if (extras.isEmpty) planExtras.remove(day);}+ for (final p in savedPlans) {+ p.drop(id);+ }if (activeRoutineId == id) activeRoutineId = null;}