Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Add dumbbells per place
InlitXd43b49cf12c3
diff --git a/lib/models/place.dart b/lib/models/place.dartindex 858e047..b0abb75 100644--- a/lib/models/place.dart+++ b/lib/models/place.dart@@ -5,6 +5,7 @@ class GymPlace {required this.equipment,this.plates = const {},this.bar,+ this.dumbbells = const [],});final String id;@@ -12,6 +13,7 @@ class GymPlace {final Set<String> equipment;final Map<double, int> plates;final double? bar;+ final List<double> dumbbells;GymPlace copyWith({String? name,@@ -19,6 +21,7 @@ class GymPlace {Map<double, int>? plates,double? bar,bool clearBar = false,+ List<double>? dumbbells,}) =>GymPlace(id: id,@@ -26,6 +29,7 @@ class GymPlace {equipment: equipment ?? this.equipment,plates: plates ?? this.plates,bar: clearBar ? null : (bar ?? this.bar),+ dumbbells: dumbbells ?? this.dumbbells,);Map<String, dynamic> toJson() => {@@ -34,6 +38,7 @@ class GymPlace {'e': equipment.toList(),if (plates.isNotEmpty) 'p': plates.map((k, v) => MapEntry(k.toString(), v)),if (bar != null) 'b': bar,+ if (dumbbells.isNotEmpty) 'db': dumbbells,};factory GymPlace.fromJson(Map<String, dynamic> j) => GymPlace(@@ -43,5 +48,6 @@ class GymPlace {plates: ((j['p'] as Map?) ?? const {}).map((k, v) => MapEntry(double.parse(k as String), (v as num).toInt())),bar: (j['b'] as num?)?.toDouble(),+ dumbbells: [for (final v in (j['db'] as List?) ?? const []) (v as num).toDouble()]..sort(),);}diff --git a/lib/screens/places_screen.dart b/lib/screens/places_screen.dartindex 1e43d46..0839acd 100644--- a/lib/screens/places_screen.dart+++ b/lib/screens/places_screen.dart@@ -1,4 +1,5 @@import 'package:flutter/material.dart';+import 'package:flutter/services.dart';import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';import '../catalog/exercise_catalog.dart';@@ -231,33 +232,15 @@ class PlacesScreen extends StatelessWidget {),if (place.equipment.contains('Barbell')) ...[const SizedBox(height: 14),- GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: () => _editPlates(context, place),- child: Container(- padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),- decoration: BoxDecoration(- color: gc.bgRaised2,- borderRadius: BorderRadius.circular(14),- ),- child: Row(- children: [- Icon(PhosphorIconsRegular.circlesThree, size: 17, color: gc.textSecondary),- const SizedBox(width: 12),- Expanded(- child: Text(t.placePlates,- style: AppTheme.s(13, weight: FontWeight.w600, color: gc.text)),- ),- Text(- place.plates.isEmpty ? t.platesAll : t.platesOwned(place.plates.length),- style: AppTheme.s(12, color: gc.textSecondary),- ),- const SizedBox(width: 6),- Icon(PhosphorIconsRegular.caretRight, size: 14, color: gc.textTertiary),- ],- ),- ),- ),+ _stockRow(gc, PhosphorIconsRegular.circlesThree, t.placePlates,+ place.plates.isEmpty ? t.platesAll : t.platesOwned(place.plates.length),+ () => _editPlates(context, place)),+ ],+ if (place.equipment.contains('Dumbbell')) ...[+ SizedBox(height: place.equipment.contains('Barbell') ? 8 : 14),+ _stockRow(gc, PhosphorIconsRegular.barbell, t.placeDumbbells,+ place.dumbbells.isEmpty ? t.platesAll : t.platesOwned(place.dumbbells.length),+ () => _editDumbbells(context, place.id)),],],),@@ -267,6 +250,133 @@ class PlacesScreen extends StatelessWidget {);}+ Widget _stockRow(GymColors gc, IconData icon, String label, String value, VoidCallback onTap) =>+ GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: Container(+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(14)),+ child: Row(+ children: [+ Icon(icon, size: 17, color: gc.textSecondary),+ const SizedBox(width: 12),+ Expanded(+ child: Text(label,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.s(13, weight: FontWeight.w600, color: gc.text)),+ ),+ const SizedBox(width: 8),+ Text(value, style: AppTheme.s(12, color: gc.textSecondary)),+ const SizedBox(width: 6),+ Icon(PhosphorIconsRegular.caretRight, size: 14, color: gc.textTertiary),+ ],+ ),+ ),+ );++ void _editDumbbells(BuildContext context, String placeId) {+ showAppSheet<void>(+ context: context,+ backgroundColor: Colors.transparent,+ isScrollControlled: true,+ builder: (sheet) => AnimatedBuilder(+ animation: fit,+ builder: (sheet, _) {+ final gc = sheet.gc;+ final place = fit.places.where((p) => p.id == placeId).firstOrNull;+ if (place == null) return const SizedBox.shrink();+ final sizes = {+ for (final s in fit.dumbbellSizes) s,+ for (final kg in place.dumbbells) (fit.toDisplayWeight(kg) * 100).round() / 100,+ }.toList()+ ..sort();+ return AppSheet(children: [+ SheetTitle(t.placeDumbbells, subtitle: t.dumbbellsHint),+ const SizedBox(height: 18),+ Wrap(+ spacing: 8,+ runSpacing: 8,+ alignment: WrapAlignment.center,+ children: [+ for (final size in sizes) _dumbbellChip(gc, place, size),+ _addDumbbellChip(sheet, gc, place),+ ],+ ),+ if (place.dumbbells.isNotEmpty) ...[+ const SizedBox(height: 6),+ GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () => fit.clearDumbbells(place.id),+ child: Container(+ height: 44,+ alignment: Alignment.center,+ child: Text(t.platesAll, style: AppTheme.s(13, weight: FontWeight.w600, color: gc.accent)),+ ),+ ),+ ] else+ const SizedBox(height: 16),+ PrimaryButton(label: t.done, onTap: () => Navigator.of(sheet).pop()),+ ]);+ },+ ),+ );+ }++ Widget _dumbbellChip(GymColors gc, GymPlace place, double size) {+ final kg = fit.fromDisplayWeight(size);+ final on = fit.ownsDumbbell(place, kg);+ return Semantics(+ button: true,+ selected: on,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () {+ HapticFeedback.selectionClick();+ fit.toggleDumbbell(place.id, kg);+ },+ child: AnimatedContainer(+ duration: const Duration(milliseconds: 160),+ constraints: const BoxConstraints(minWidth: 52),+ height: 36,+ padding: const EdgeInsets.symmetric(horizontal: 12),+ alignment: Alignment.center,+ decoration: BoxDecoration(+ color: on ? gc.emberSoft : gc.bgRaised2,+ borderRadius: BorderRadius.circular(100),+ border: Border.all(color: on ? gc.ember : gc.border),+ ),+ child: Text(fmt(size),+ style: AppTheme.f(13, weight: FontWeight.w700, color: on ? gc.text : gc.textSecondary)),+ ),+ ),+ );+ }++ Widget _addDumbbellChip(BuildContext context, GymColors gc, GymPlace place) => Semantics(+ button: true,+ label: t.dumbbellOther,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () async {+ final v = await askNumber(context, title: t.dumbbellOther, initial: '', decimal: true);+ if (v != null && v > 0) fit.toggleDumbbell(place.id, fit.fromDisplayWeight(v));+ },+ child: Container(+ width: 52,+ height: 36,+ alignment: Alignment.center,+ decoration: BoxDecoration(+ color: gc.bgRaised2,+ borderRadius: BorderRadius.circular(100),+ border: Border.all(color: gc.border),+ ),+ child: Icon(PhosphorIconsBold.plus, size: 13, color: gc.textSecondary),+ ),+ ),+ );+Widget _gearChip(GymColors gc, GymPlace place, String gear) {final on = place.equipment.contains(gear) || gear == 'Bodyweight';final locked = gear == 'Bodyweight';diff --git a/lib/state/places_state.dart b/lib/state/places_state.dartindex 2e2aa05..e040efc 100644--- a/lib/state/places_state.dart+++ b/lib/state/places_state.dart@@ -100,6 +100,40 @@ mixin PlacesState on FitCore, LibraryState {@overridedouble? get placeBarKg => activePlace?.bar;+ @override+ List<double>? dumbbellStockFor(String id) {+ final owned = activePlace?.dumbbells;+ if (owned == null || owned.isEmpty || exerciseById(id)?.equipment != 'Dumbbell' || isAssisted(id)) return null;+ return owned;+ }++ List<double> get dumbbellSizes => isLb+ ? const [5, 8, 10, 12, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 90, 100]+ : const [1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9, 10, 12, 12.5, 14, 15, 16, 17.5, 18, 20, 22, 22.5, 24, 25, 26,+ 27.5, 28, 30, 32, 32.5, 34, 35, 36, 37.5, 40, 42.5, 45, 47.5, 50];++ bool ownsDumbbell(GymPlace place, double kg) => place.dumbbells.any((v) => (v - kg).abs() < 0.05);++ void toggleDumbbell(String placeId, double kg) {+ final i = places.indexWhere((p) => p.id == placeId);+ if (i < 0 || kg <= 0) return;+ final list = [...places[i].dumbbells];+ final at = list.indexWhere((v) => (v - kg).abs() < 0.05);+ at >= 0 ? list.removeAt(at) : list.add(_round3(kg));+ list.sort();+ places[i] = places[i].copyWith(dumbbells: list);+ _persist();+ notifyListeners();+ }++ void clearDumbbells(String placeId) {+ final i = places.indexWhere((p) => p.id == placeId);+ if (i < 0) return;+ places[i] = places[i].copyWith(dumbbells: const []);+ _persist();+ notifyListeners();+ }+void setPlatePairs(String placeId, double kg, int pairs) {final i = places.indexWhere((p) => p.id == placeId);if (i < 0) return;diff --git a/test/places_test.dart b/test/places_test.dartindex 30b2332..722917c 100644--- a/test/places_test.dart+++ b/test/places_test.dart@@ -126,6 +126,29 @@ void main() {expect(fit.exercisesFiltered.length, fit.allExercises.length);});+ test('the dumbbells you own steer the weights of dumbbell work here, and only here', () {+ final id = fit.addPlace('Casa', equipment: {'Dumbbell', 'Barbell'});+ for (final kg in [12.5, 5.0, 10.0, 7.5]) {+ fit.toggleDumbbell(id, kg);+ }+ fit.toggleDumbbell(id, 7.5);+ expect(fit.places.single.dumbbells, [5.0, 10.0, 12.5]);+ final curl = fit.allExercises.firstWhere((e) => e.equipment == 'Dumbbell' && !fit.isAssisted(e.id)).id;+ final bar = fit.allExercises.firstWhere((e) => e.equipment == 'Barbell').id;+ expect(fit.stackFor(curl), isNull, reason: 'sin estar en el sitio no manda');+ fit.setActivePlace(id);+ expect(fit.stackFor(curl), [5.0, 10.0, 12.5]);+ expect(fit.ownStackFor(curl), isNull);+ expect(fit.stackFor(bar), isNull);+ expect(fit.snapToStack(curl, 10, dir: 1), 12.5);+ fit.persistNow();+ fit.places.clear();+ fit.loadFromStore();+ expect(fit.places.single.dumbbells, [5.0, 10.0, 12.5]);+ fit.clearDumbbells(id);+ expect(fit.stackFor(curl), isNull);+ });+test('an exercise you cannot do here offers what you can', () {final id = fit.addPlace('Casa', equipment: {'Dumbbell'});fit.setActivePlace(id);