Skip to content

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

Say where you train and what kit is there, and filter the library by it

InlitXfdb04026d14b
diff --git a/lib/models/place.dart b/lib/models/place.dart
new file mode 100644
index 0000000..4b3ae38
--- /dev/null
+++ b/lib/models/place.dart
@@ -0,0 +1,25 @@
+class GymPlace {
+ const GymPlace({required this.id, required this.name, required this.equipment});
+
+ final String id;
+ final String name;
+ final Set<String> equipment;
+
+ GymPlace copyWith({String? name, Set<String>? equipment}) => GymPlace(
+ id: id,
+ name: name ?? this.name,
+ equipment: equipment ?? this.equipment,
+ );
+
+ Map<String, dynamic> toJson() => {
+ 'id': id,
+ 'n': name,
+ 'e': equipment.toList(),
+ };
+
+ factory GymPlace.fromJson(Map<String, dynamic> j) => GymPlace(
+ id: (j['id'] ?? '') as String,
+ name: (j['n'] ?? '') as String,
+ equipment: ((j['e'] as List?) ?? const []).cast<String>().toSet(),
+ );
+}
diff --git a/lib/screens/exercises_screen.dart b/lib/screens/exercises_screen.dart
index c712842..705517d 100644
--- a/lib/screens/exercises_screen.dart
+++ b/lib/screens/exercises_screen.dart
@@ -122,6 +122,17 @@ class _ExercisesScreenState extends State<ExercisesScreen> {
),
),
const SizedBox(height: 14),
+ _filterLabel(gc, t.placeFilterLabel),
+ const SizedBox(height: 8),
+ _chipRow([
+ _FilterChipData(t.placeAll, fit.activePlaceId.isEmpty,
+ () => fit.setActivePlace('')),
+ for (final place in fit.places)
+ _FilterChipData(place.name, fit.activePlaceId == place.id,
+ () => fit.setActivePlace(place.id)),
+ _FilterChipData(fit.places.isEmpty ? t.placeNew : '+', false, fit.goPlaces),
+ ], gc, hPad: 14, vPad: 8, fontSize: 13),
+ const SizedBox(height: 14),
_filterLabel(gc, t.muscleFilter),
const SizedBox(height: 8),
_chipRow([
@@ -129,6 +140,15 @@ class _ExercisesScreenState extends State<ExercisesScreen> {
_FilterChipData(muscleLabel(id), fit.exMuscleFilter == id, () => fit.setMuscleFilter(id)),
], gc, hPad: 14, vPad: 8, fontSize: 13),
const SizedBox(height: 14),
+ _filterLabel(gc, t.equipmentLabel),
+ const SizedBox(height: 8),
+ _chipRow([
+ _FilterChipData(t.noGearOnly, fit.exNoGearOnly, fit.toggleNoGearFilter),
+ for (final e in kFilterEquipment)
+ _FilterChipData(
+ t.equipment(e), fit.exEquipmentFilter == e, () => fit.setEquipmentFilter(e)),
+ ], gc, hPad: 12, vPad: 6, fontSize: 12),
+ const SizedBox(height: 14),
_filterLabel(gc, t.levelFilter),
const SizedBox(height: 8),
_chipRow([
diff --git a/lib/screens/places_screen.dart b/lib/screens/places_screen.dart
new file mode 100644
index 0000000..f674a8c
--- /dev/null
+++ b/lib/screens/places_screen.dart
@@ -0,0 +1,351 @@
+import 'package:flutter/material.dart';
+import 'package:phosphor_flutter/phosphor_flutter.dart';
+
+import '../catalog/exercise_catalog.dart';
+import '../l10n/l10n.dart';
+import '../models/place.dart';
+import '../state/fit_state.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+import '../widgets/svg_icon.dart';
+import '../widgets/ui_kit.dart';
+
+class PlacesScreen extends StatelessWidget {
+ const PlacesScreen({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final places = fit.places;
+
+ return SafeArea(
+ bottom: false,
+ child: Column(
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 12, 20, 0),
+ child: Row(
+ children: [
+ RoundBtn(icon: Ic.chevronLeft, onTap: fit.backFromPlaces),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ ScreenTitle(t.places, size: 20),
+ const SizedBox(height: 2),
+ Text(
+ fit.activePlace == null
+ ? t.placeAll
+ : t.placeActive(fit.activePlace!.name),
+ style: AppTheme.s(12.5, color: gc.textSecondary)),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ Expanded(
+ child: ListView(
+ padding: const EdgeInsets.fromLTRB(20, 18, 20, 20),
+ children: [
+ Text(t.placesHint, style: AppTheme.s(13, color: gc.textSecondary, height: 1.5)),
+ const SizedBox(height: 18),
+ if (places.isEmpty) _empty(context, gc),
+ for (final place in places) ...[
+ _card(context, gc, place),
+ const SizedBox(height: 12),
+ ],
+ const SizedBox(height: 4),
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => _rename(context, null),
+ child: Container(
+ height: 50,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(16),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(PhosphorIconsRegular.plus, size: 16, color: gc.ember),
+ const SizedBox(width: 8),
+ Text(t.placeNew,
+ style: AppTheme.d(13,
+ weight: FontWeight.w600, color: gc.text, letterSpacing: 1)),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _empty(BuildContext context, GymColors gc) => Container(
+ margin: const EdgeInsets.only(bottom: 16),
+ padding: const EdgeInsets.fromLTRB(20, 22, 20, 20),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(t.placeEmptyTitle,
+ style: AppTheme.d(17, weight: FontWeight.w700, color: gc.text)),
+ const SizedBox(height: 6),
+ Text(t.placeEmptyBody,
+ style: AppTheme.s(13, color: gc.textSecondary, height: 1.5)),
+ const SizedBox(height: 16),
+ Row(
+ children: [
+ for (final preset in kPlacePresets) ...[
+ if (preset != kPlacePresets.first) const SizedBox(width: 8),
+ Expanded(
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => fit.setActivePlace(fit.addPresetPlace(preset)),
+ child: Container(
+ height: 44,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ color: gc.bgRaised2,
+ border: Border.all(color: gc.border),
+ borderRadius: BorderRadius.circular(14),
+ ),
+ child: FittedBox(
+ fit: BoxFit.scaleDown,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 8),
+ child: Text(t.placePresetName(preset),
+ maxLines: 1,
+ style: AppTheme.s(13,
+ weight: FontWeight.w600, color: gc.text)),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ],
+ ),
+ ],
+ ),
+ );
+
+ Widget _card(BuildContext context, GymColors gc, GymPlace place) {
+ final on = fit.activePlaceId == place.id;
+
+ return Container(
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ border: Border.all(color: on ? gc.ember : gc.border),
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: Column(
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 14, 12, 10),
+ child: Row(
+ children: [
+ Semantics(
+ button: true,
+ selected: on,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => fit.setActivePlace(place.id),
+ child: Container(
+ width: 26,
+ height: 26,
+ decoration: BoxDecoration(
+ color: on ? gc.ember : Colors.transparent,
+ shape: BoxShape.circle,
+ border: Border.all(color: on ? gc.ember : gc.border, width: 1.5),
+ ),
+ child: on
+ ? Icon(PhosphorIconsBold.check, size: 14, color: gc.onEmber)
+ : null,
+ ),
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => fit.setActivePlace(place.id),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(place.name,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.d(17, weight: FontWeight.w700, color: gc.text)),
+ const SizedBox(height: 2),
+ Text(t.placeExercises(fit.placeExerciseCount(place)),
+ style: AppTheme.s(12, color: gc.textTertiary)),
+ ],
+ ),
+ ),
+ ),
+ Semantics(
+ button: true,
+ label: t.editEntry,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => _rename(context, place),
+ child: Padding(
+ padding: const EdgeInsets.all(8),
+ child: Icon(PhosphorIconsRegular.pencilSimple, size: 16, color: gc.textSecondary),
+ ),
+ ),
+ ),
+ Semantics(
+ button: true,
+ label: t.delete,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => _confirmDelete(context, place),
+ child: Padding(
+ padding: const EdgeInsets.all(8),
+ child: Icon(PhosphorIconsRegular.trash, size: 16, color: gc.textTertiary),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(t.placeGearLabel,
+ style: AppTheme.s(10,
+ weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.5)),
+ const SizedBox(height: 10),
+ Wrap(
+ spacing: 8,
+ runSpacing: 8,
+ children: [
+ for (final gear in kEquipment)
+ _gearChip(gc, place, gear),
+ ],
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _gearChip(GymColors gc, GymPlace place, String gear) {
+ final on = place.equipment.contains(gear) || gear == 'Bodyweight';
+ final locked = gear == 'Bodyweight';
+
+ return Semantics(
+ button: !locked,
+ selected: on,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: locked ? null : () => fit.togglePlaceGear(place.id, gear),
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 7),
+ decoration: BoxDecoration(
+ color: on ? gc.emberSoft : gc.bgRaised2,
+ borderRadius: BorderRadius.circular(100),
+ border: Border.all(color: on ? gc.ember : gc.border),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(on ? PhosphorIconsBold.check : PhosphorIconsBold.plus,
+ size: 10, color: on ? gc.ember : gc.textTertiary),
+ const SizedBox(width: 6),
+ Text(t.equipment(gear),
+ style: AppTheme.s(12.5,
+ weight: FontWeight.w600, color: on ? gc.text : gc.textSecondary)),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+
+ Future<void> _rename(BuildContext context, GymPlace? place) async {
+ final gc = context.gc;
+ final controller = TextEditingController(text: place?.name ?? '');
+ final name = await showDialog<String>(
+ context: context,
+ builder: (dctx) => AlertDialog(
+ backgroundColor: gc.bgRaised,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
+ title: Text(place == null ? t.placeNew : t.editEntry,
+ style: AppTheme.d(18, weight: FontWeight.w700, color: gc.text)),
+ content: TextField(
+ controller: controller,
+ autofocus: true,
+ textCapitalization: TextCapitalization.sentences,
+ style: AppTheme.s(15, color: gc.text),
+ cursorColor: gc.accent,
+ decoration: InputDecoration(
+ hintText: t.placeNamePlaceholder,
+ hintStyle: AppTheme.s(15, color: gc.textTertiary),
+ enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: gc.border)),
+ focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: gc.accent)),
+ ),
+ onSubmitted: (v) => Navigator.of(dctx).pop(v),
+ ),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.of(dctx).pop(),
+ child: Text(t.cancel, style: AppTheme.s(14, color: gc.textSecondary)),
+ ),
+ TextButton(
+ onPressed: () => Navigator.of(dctx).pop(controller.text),
+ child: Text(t.save, style: AppTheme.s(14, weight: FontWeight.w700, color: gc.accent)),
+ ),
+ ],
+ ),
+ );
+ controller.dispose();
+ if (name == null || name.trim().isEmpty) return;
+ if (place == null) {
+ fit.setActivePlace(fit.addPlace(name));
+ } else {
+ fit.renamePlace(place.id, name);
+ }
+ }
+
+ Future<void> _confirmDelete(BuildContext context, GymPlace place) async {
+ final gc = context.gc;
+ final ok = await showDialog<bool>(
+ context: context,
+ builder: (dctx) => AlertDialog(
+ backgroundColor: gc.bgRaised,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
+ title: Text(t.placeDeleteTitle,
+ style: AppTheme.d(18, weight: FontWeight.w700, color: gc.text)),
+ content: Text(t.placeDeleteBody, style: AppTheme.s(13, color: gc.textSecondary)),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.of(dctx).pop(false),
+ child: Text(t.cancel, style: AppTheme.s(14, color: gc.textSecondary)),
+ ),
+ TextButton(
+ onPressed: () => Navigator.of(dctx).pop(true),
+ child: Text(t.delete, style: AppTheme.s(14, weight: FontWeight.w700, color: gc.danger)),
+ ),
+ ],
+ ),
+ );
+ if (ok == true) fit.deletePlace(place.id);
+ }
+}
diff --git a/lib/state/places_state.dart b/lib/state/places_state.dart
new file mode 100644
index 0000000..4cad9e7
--- /dev/null
+++ b/lib/state/places_state.dart
@@ -0,0 +1,120 @@
+part of 'fit_state.dart';
+
+const List<String> kPlacePresets = ['gym', 'home', 'outdoors'];
+
+const Map<String, List<String>> kPlacePresetGear = {
+ 'gym': kEquipment,
+ 'home': ['Bodyweight', 'Dumbbell', 'Kettlebell', 'Band', 'Weighted'],
+ 'outdoors': ['Bodyweight', 'Band'],
+};
+
+mixin PlacesState on FitCore, LibraryState {
+ String activePlaceId = '';
+ int _placeSeq = 0;
+
+ GymPlace? get activePlace {
+ for (final p in places) {
+ if (p.id == activePlaceId) return p;
+ }
+ return null;
+ }
+
+ /// Sin sitio elegido cabe todo; el peso corporal nunca necesita material.
+ Set<String> get gearHere {
+ final place = activePlace;
+ return place == null ? kEquipment.toSet() : {...place.equipment, 'Bodyweight'};
+ }
+
+ bool fitsHere(Exercise ex) => activePlace == null || gearHere.contains(ex.equipment);
+
+ int placeExerciseCount(GymPlace place) {
+ final gear = {...place.equipment, 'Bodyweight'};
+ return allExercises.where((e) => gear.contains(e.equipment)).length;
+ }
+
+ List<Exercise> alternativesHere(Exercise ex, int n) {
+ if (fitsHere(ex)) return const [];
+ final pool = allExercises
+ .where((e) => e.id != ex.id && e.primary == ex.primary && fitsHere(e))
+ .toList();
+ pool.sort((a, b) {
+ int rank(Exercise e) {
+ if (favorites[e.id] == true) return 0;
+ return e.equipment == 'Bodyweight' ? 1 : 2;
+ }
+
+ return rank(a).compareTo(rank(b));
+ });
+ return pool.take(n).toList();
+ }
+
+ String addPlace(String name, {Set<String> equipment = const {'Bodyweight'}}) {
+ final clean = name.trim();
+ if (clean.isEmpty) return '';
+ final id = 'p${DateTime.now().microsecondsSinceEpoch}-${_placeSeq++}';
+ places.add(GymPlace(id: id, name: clean, equipment: {...equipment}));
+ _persist();
+ notifyListeners();
+ return id;
+ }
+
+ String addPresetPlace(String preset) => addPlace(
+ t.placePresetName(preset),
+ equipment: (kPlacePresetGear[preset] ?? const ['Bodyweight']).toSet(),
+ );
+
+ void renamePlace(String id, String name) {
+ final i = places.indexWhere((p) => p.id == id);
+ final clean = name.trim();
+ if (i < 0 || clean.isEmpty) return;
+ places[i] = places[i].copyWith(name: clean);
+ _persist();
+ notifyListeners();
+ }
+
+ void togglePlaceGear(String id, String equipment) {
+ final i = places.indexWhere((p) => p.id == id);
+ if (i < 0) return;
+ final gear = {...places[i].equipment};
+ gear.contains(equipment) ? gear.remove(equipment) : gear.add(equipment);
+ places[i] = places[i].copyWith(equipment: gear);
+ _persist();
+ notifyListeners();
+ }
+
+ void deletePlace(String id) {
+ places.removeWhere((p) => p.id == id);
+ if (activePlaceId == id) activePlaceId = '';
+ _persist();
+ notifyListeners();
+ }
+
+ void setActivePlace(String id) {
+ activePlaceId = activePlaceId == id ? '' : id;
+ _persist();
+ notifyListeners();
+ }
+
+ bool exNoGearOnly = false;
+
+ void toggleNoGearFilter() {
+ exNoGearOnly = !exNoGearOnly;
+ notifyListeners();
+ }
+
+ @override
+ List<Exercise> get exercisesFiltered => super
+ .exercisesFiltered
+ .where((ex) => (!exNoGearOnly || ex.equipment == 'Bodyweight') && fitsHere(ex))
+ .toList();
+
+ @override
+ void clearExFilters() {
+ exNoGearOnly = false;
+ super.clearExFilters();
+ }
+
+ void goPlaces() => pushRoute('places');
+
+ void backFromPlaces() => popRoute(fallback: 'settings');
+}
diff --git a/test/places_test.dart b/test/places_test.dart
new file mode 100644
index 0000000..1725916
--- /dev/null
+++ b/test/places_test.dart
@@ -0,0 +1,187 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:gymmane/app/gymmane_app.dart';
+import 'package:gymmane/l10n/l10n.dart';
+import 'package:gymmane/screens/places_screen.dart';
+import 'package:gymmane/services/local_store.dart';
+import 'package:gymmane/state/fit_state.dart';
+import 'package:gymmane/theme/app_theme.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+
+Widget _host(Widget Function() screen) => MaterialApp(
+ theme: AppTheme.dark,
+ home: AnimatedBuilder(
+ animation: fit,
+ builder: (_, _) => Scaffold(body: screen()),
+ ),
+ );
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ setUp(() async {
+ SharedPreferences.setMockInitialValues({});
+ await Store.instance.init();
+ setAppLanguage('es');
+ fit.places.clear();
+ fit.activePlaceId = '';
+ fit.exNoGearOnly = false;
+ fit.clearExFilters();
+ fit.onboarded = true;
+ });
+
+ tearDown(() {
+ fit.places.clear();
+ fit.activePlaceId = '';
+ fit.exNoGearOnly = false;
+ fit.persistNow();
+ });
+
+ test('with no place picked the whole library is on the table', () {
+ final all = fit.exercisesFiltered.length;
+ expect(all, greaterThan(400));
+ expect(fit.activePlace, isNull);
+ expect(fit.fitsHere(fit.allExercises.firstWhere((e) => e.equipment == 'Machine')), true);
+ });
+
+ test('a place only shows what its kit can do, and bodyweight always fits', () {
+ final id = fit.addPlace('Casa', equipment: {'Dumbbell'});
+ fit.setActivePlace(id);
+
+ final list = fit.exercisesFiltered;
+ expect(list, isNotEmpty);
+ expect(list.every((e) => e.equipment == 'Dumbbell' || e.equipment == 'Bodyweight'), true);
+ expect(list.any((e) => e.equipment == 'Bodyweight'), true,
+ reason: 'sin material siempre se puede');
+ expect(list.length, lessThan(fit.allExercises.length));
+ });
+
+ test('the kettlebell preset brings the kettlebell work in', () {
+ final id = fit.addPlace('Casa', equipment: {'Kettlebell'});
+ fit.setActivePlace(id);
+ final list = fit.exercisesFiltered;
+
+ expect(list.where((e) => e.equipment == 'Kettlebell').length, greaterThanOrEqualTo(15));
+ expect(list.any((e) => e.equipment == 'Barbell'), false);
+ });
+
+ test('the no-kit toggle leaves bodyweight only', () {
+ fit.toggleNoGearFilter();
+ expect(fit.exercisesFiltered.every((e) => e.equipment == 'Bodyweight'), true);
+
+ fit.toggleNoGearFilter();
+ expect(fit.exercisesFiltered.any((e) => e.equipment != 'Bodyweight'), true);
+ });
+
+ test('clearing the filters also drops the no-kit toggle but keeps the place', () {
+ final id = fit.addPlace('Casa', equipment: {'Dumbbell'});
+ fit.setActivePlace(id);
+ fit.toggleNoGearFilter();
+ fit.clearExFilters();
+
+ expect(fit.exNoGearOnly, false);
+ expect(fit.activePlaceId, id, reason: 'el sitio es un modo, no un filtro de la lista');
+ });
+
+ test('the workout picker only suggests what the place can do', () {
+ final id = fit.addPlace('Parque', equipment: {'Bodyweight'});
+ fit.setActivePlace(id);
+
+ final picks = fit.getFilteredExercises(['chest']);
+ expect(picks, isNotEmpty);
+ expect(picks.every((e) => e.equipment == 'Bodyweight'), true);
+ });
+
+ test('presets land with their own kit', () {
+ final id = fit.addPresetPlace('home');
+ final place = fit.places.single;
+
+ expect(place.id, id);
+ expect(place.equipment, contains('Kettlebell'));
+ expect(place.equipment.contains('Machine'), false);
+ expect(fit.placeExerciseCount(place), greaterThan(50));
+ });
+
+ test('places survive a save and a reload, and the active one with them', () {
+ final id = fit.addPlace('Gimnasio', equipment: {'Barbell', 'Machine'});
+ fit.setActivePlace(id);
+ fit.persistNow();
+
+ fit.places.clear();
+ fit.activePlaceId = '';
+ fit.loadFromStore();
+
+ expect(fit.places.single.name, 'Gimnasio');
+ expect(fit.places.single.equipment, {'Barbell', 'Machine'});
+ expect(fit.activePlaceId, id);
+ });
+
+ test('deleting the place you are at puts you back everywhere', () {
+ final id = fit.addPlace('Casa', equipment: {'Dumbbell'});
+ fit.setActivePlace(id);
+ fit.deletePlace(id);
+
+ expect(fit.places, isEmpty);
+ expect(fit.activePlaceId, '');
+ expect(fit.exercisesFiltered.length, fit.allExercises.length);
+ });
+
+ test('an exercise you cannot do here offers what you can', () {
+ final id = fit.addPlace('Casa', equipment: {'Dumbbell'});
+ fit.setActivePlace(id);
+ final barbell = fit.allExercises.firstWhere((e) => e.equipment == 'Barbell');
+
+ final alts = fit.alternativesHere(barbell, 3);
+ expect(alts, isNotEmpty);
+ expect(alts.every((e) => e.primary == barbell.primary), true);
+ expect(alts.every(fit.fitsHere), true);
+
+ final dumbbell = fit.allExercises.firstWhere((e) => e.equipment == 'Dumbbell');
+ expect(fit.alternativesHere(dumbbell, 3), isEmpty, reason: 'ese sí se puede hacer aquí');
+ });
+
+ testWidgets('picking a place on its screen switches where you train', (tester) async {
+ fit.addPlace('Casa', equipment: {'Dumbbell'});
+ fit.goPlaces();
+ await tester.pumpWidget(_host(PlacesScreen.new));
+ await tester.pumpAndSettle();
+
+ expect(find.text('Casa'), findsOneWidget);
+ await tester.tap(find.text('Casa'));
+ await tester.pumpAndSettle();
+
+ expect(fit.activePlace?.name, 'Casa');
+ fit.persistNow();
+ });
+
+ testWidgets('the empty screen offers the three starters', (tester) async {
+ fit.goPlaces();
+ await tester.pumpWidget(_host(PlacesScreen.new));
+ await tester.pumpAndSettle();
+
+ expect(find.text(t.placeEmptyTitle), findsOneWidget);
+ await tester.tap(find.text(t.placeHome));
+ await tester.pumpAndSettle();
+
+ expect(fit.places.single.name, t.placeHome);
+ expect(fit.activePlaceId, fit.places.single.id);
+ fit.persistNow();
+ });
+
+ testWidgets('the library screen carries the place chips', (tester) async {
+ fit.addPlace('Casa', equipment: {'Dumbbell'});
+ fit.route = 'exercises';
+ await tester.pumpWidget(const GymManeApp());
+ await tester.pumpAndSettle();
+
+ expect(find.text(t.placeAll), findsOneWidget);
+ await tester.tap(find.text('Casa'));
+ await tester.pumpAndSettle();
+ expect(fit.activePlace?.name, 'Casa');
+
+ await tester.tap(find.text(t.placeAll));
+ await tester.pumpAndSettle();
+ expect(fit.activePlaceId, '');
+ fit.persistNow();
+ });
+}