diff --git a/lib/features/routines/widgets/gym_mode/start_page.dart b/lib/features/routines/widgets/gym_mode/start_page.dart index 046ef90b0..160634a63 100644 --- a/lib/features/routines/widgets/gym_mode/start_page.dart +++ b/lib/features/routines/widgets/gym_mode/start_page.dart @@ -29,7 +29,10 @@ import 'package:wger/features/routines/widgets/gym_mode/navigation.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; class GymModeOptions extends ConsumerStatefulWidget { - const GymModeOptions({super.key}); + /// Height the options take at most, the opened card shrinks and scrolls + final double maxHeight; + + const GymModeOptions({super.key, this.maxHeight = double.infinity}); @override ConsumerState createState() => _GymModeOptionsState(); @@ -65,194 +68,201 @@ class _GymModeOptionsState extends ConsumerState { _countdownController.text = currentText; } - return Column( - children: [ - AnimatedCrossFade( - firstChild: const SizedBox.shrink(), - secondChild: Padding( - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), - child: ConstrainedBox( - constraints: const BoxConstraints(maxHeight: 400), - child: Card( - child: SingleChildScrollView( - child: Column( - children: [ - SwitchListTile( - key: const ValueKey('gym-mode-option-show-exercises'), - title: Text(i18n.gymModeShowExercises), - value: gymState.showExercisePages, - onChanged: (value) => gymNotifier.setShowExercisePages(value), - ), - SwitchListTile( - key: const ValueKey('gym-mode-option-show-workout-duration'), - title: Text(i18n.gymModeShowWorkoutDuration), - value: gymState.showWorkoutDuration, - onChanged: (value) => gymNotifier.setShowWorkoutDuration(value), - ), + return ConstrainedBox( + constraints: BoxConstraints(maxHeight: widget.maxHeight), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Flexible( + child: AnimatedCrossFade( + firstChild: const SizedBox.shrink(), + secondChild: Padding( + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), + child: ConstrainedBox( + constraints: const BoxConstraints(maxHeight: 400), + child: Card( + child: SingleChildScrollView( + child: Column( + children: [ + SwitchListTile( + key: const ValueKey('gym-mode-option-show-exercises'), + title: Text(i18n.gymModeShowExercises), + value: gymState.showExercisePages, + onChanged: (value) => gymNotifier.setShowExercisePages(value), + ), + SwitchListTile( + key: const ValueKey('gym-mode-option-show-workout-duration'), + title: Text(i18n.gymModeShowWorkoutDuration), + value: gymState.showWorkoutDuration, + onChanged: (value) => gymNotifier.setShowWorkoutDuration(value), + ), - const Divider(), - SwitchListTile( - key: const ValueKey('gym-mode-option-show-timer'), - title: Text(i18n.gymModeShowTimer), - value: gymState.showTimerPages, - onChanged: (value) => gymNotifier.setShowTimerPages(value), - ), - ListTile( - key: const ValueKey('gym-mode-timer-type'), - enabled: gymState.showTimerPages, - title: Text(i18n.gymModeTimerType), - trailing: DropdownButton( - key: const ValueKey('countdown-type-dropdown'), - value: gymState.useCountdownBetweenSets, - onChanged: gymState.showTimerPages - ? (bool? newValue) { - if (newValue != null) { - gymNotifier.setUseCountdownBetweenSets(newValue); - } - } - : null, - items: [false, true].map>((bool value) { - final label = value ? i18n.countdown : i18n.stopwatch; - - return DropdownMenuItem(value: value, child: Text(label)); - }).toList(), - ), - subtitle: Text(i18n.gymModeTimerTypeHelText), - ), - ListTile( - key: const ValueKey('gym-mode-default-countdown-time'), - enabled: gymState.showTimerPages, - title: TextFormField( - controller: _countdownController, - keyboardType: TextInputType.number, - decoration: InputDecoration( - labelText: i18n.gymModeDefaultCountdownTime, - suffix: IconButton( - onPressed: gymState.showTimerPages && gymState.useCountdownBetweenSets - ? () => gymNotifier.setCountdownDuration( - DEFAULT_COUNTDOWN_DURATION, - ) + const Divider(), + SwitchListTile( + key: const ValueKey('gym-mode-option-show-timer'), + title: Text(i18n.gymModeShowTimer), + value: gymState.showTimerPages, + onChanged: (value) => gymNotifier.setShowTimerPages(value), + ), + ListTile( + key: const ValueKey('gym-mode-timer-type'), + enabled: gymState.showTimerPages, + title: Text(i18n.gymModeTimerType), + trailing: DropdownButton( + key: const ValueKey('countdown-type-dropdown'), + value: gymState.useCountdownBetweenSets, + onChanged: gymState.showTimerPages + ? (bool? newValue) { + if (newValue != null) { + gymNotifier.setUseCountdownBetweenSets(newValue); + } + } : null, - icon: const Icon(Icons.refresh), + items: [false, true].map>((bool value) { + final label = value ? i18n.countdown : i18n.stopwatch; + + return DropdownMenuItem(value: value, child: Text(label)); + }).toList(), + ), + subtitle: Text(i18n.gymModeTimerTypeHelText), + ), + ListTile( + key: const ValueKey('gym-mode-default-countdown-time'), + enabled: gymState.showTimerPages, + title: TextFormField( + controller: _countdownController, + keyboardType: TextInputType.number, + decoration: InputDecoration( + labelText: i18n.gymModeDefaultCountdownTime, + suffix: IconButton( + onPressed: + gymState.showTimerPages && gymState.useCountdownBetweenSets + ? () => gymNotifier.setCountdownDuration( + DEFAULT_COUNTDOWN_DURATION, + ) + : null, + icon: const Icon(Icons.refresh), + ), + ), + onChanged: (value) { + final intValue = int.tryParse(value); + if (intValue != null && + intValue > 0 && + intValue < MAX_COUNTDOWN_DURATION) { + gymNotifier.setCountdownDuration(intValue); + } + }, + autovalidateMode: AutovalidateMode.onUserInteraction, + validator: (String? value) { + final intValue = int.tryParse(value!); + if (intValue == null || + intValue < MIN_COUNTDOWN_DURATION || + intValue > MAX_COUNTDOWN_DURATION) { + return i18n.formMinMaxValues( + MIN_COUNTDOWN_DURATION, + MAX_COUNTDOWN_DURATION, + ); + } + return null; + }, + enabled: gymState.showTimerPages && gymState.useCountdownBetweenSets, ), ), - onChanged: (value) { - final intValue = int.tryParse(value); - if (intValue != null && - intValue > 0 && - intValue < MAX_COUNTDOWN_DURATION) { - gymNotifier.setCountdownDuration(intValue); - } - }, - autovalidateMode: AutovalidateMode.onUserInteraction, - validator: (String? value) { - final intValue = int.tryParse(value!); - if (intValue == null || - intValue < MIN_COUNTDOWN_DURATION || - intValue > MAX_COUNTDOWN_DURATION) { - return i18n.formMinMaxValues( - MIN_COUNTDOWN_DURATION, - MAX_COUNTDOWN_DURATION, - ); - } - return null; - }, - enabled: gymState.showTimerPages && gymState.useCountdownBetweenSets, - ), - ), - SwitchListTile( - key: const ValueKey('gym-mode-notify-countdown'), - title: Text(i18n.gymModeNotifyOnCountdownFinish), - value: gymState.alertOnCountdownEnd, - onChanged: (gymState.showTimerPages && gymState.useCountdownBetweenSets) - ? (value) => gymNotifier.setAlertOnCountdownEnd(value) - : null, - ), - SwitchListTile( - key: const ValueKey('gym-mode-rest-alarm'), - title: Text(i18n.gymModeRestAlarm), - subtitle: Text(i18n.gymModeRestAlarmHelp), - value: gymState.restAlarmEnabled, - onChanged: gymState.showTimerPages - ? (value) => gymNotifier.setRestAlarmEnabled(value) - : null, - ), - // Android delays alarms without the exact alarm permission - if (isAndroid && - gymState.showTimerPages && - gymState.restAlarmEnabled && - ref.watch(exactAlarmsAllowedProvider).value == false) - ListTile( - key: const ValueKey('gym-mode-exact-alarm-hint'), - leading: const Icon(Icons.alarm_off), - title: Text(i18n.gymModeExactAlarmMissing), - trailing: TextButton( - onPressed: () async { - await ref - .read(workoutNotificationServiceProvider) - .requestExactAlarms(); - ref.invalidate(exactAlarmsAllowedProvider); - }, - child: Text(i18n.gymModeExactAlarmAllow), + SwitchListTile( + key: const ValueKey('gym-mode-notify-countdown'), + title: Text(i18n.gymModeNotifyOnCountdownFinish), + value: gymState.alertOnCountdownEnd, + onChanged: (gymState.showTimerPages && gymState.useCountdownBetweenSets) + ? (value) => gymNotifier.setAlertOnCountdownEnd(value) + : null, ), - ), - // The ongoing notification only exists on Android - if (isAndroid) - SwitchListTile( - key: const ValueKey('gym-mode-workout-notification'), - title: Text(i18n.gymModeWorkoutNotification), - subtitle: Text(i18n.gymModeWorkoutNotificationHelp), - value: gymState.showWorkoutNotification, - onChanged: (value) => gymNotifier.setShowWorkoutNotification(value), - ), - - const Divider(), - ListTile( - key: const ValueKey('gym-mode-log-scope'), - title: Text(i18n.gymModeLogScope), - subtitle: Text(i18n.gymModeLogScopeHelp), - trailing: DropdownButton( - key: const ValueKey('log-scope-dropdown'), - value: gymState.logScopeWeeks, - onChanged: (value) => gymNotifier.setLogScopeWeeks(value), - items: [ - DropdownMenuItem( - value: null, - child: Text(i18n.gymModeLogScopeCurrentRoutine), - ), - ...[8, 12, 25, 50].map( - (weeks) => DropdownMenuItem( - value: weeks, - child: Text(i18n.gymModeLogScopeWeeks(weeks)), + SwitchListTile( + key: const ValueKey('gym-mode-rest-alarm'), + title: Text(i18n.gymModeRestAlarm), + subtitle: Text(i18n.gymModeRestAlarmHelp), + value: gymState.restAlarmEnabled, + onChanged: gymState.showTimerPages + ? (value) => gymNotifier.setRestAlarmEnabled(value) + : null, + ), + // Android delays alarms without the exact alarm permission + if (isAndroid && + gymState.showTimerPages && + gymState.restAlarmEnabled && + ref.watch(exactAlarmsAllowedProvider).value == false) + ListTile( + key: const ValueKey('gym-mode-exact-alarm-hint'), + leading: const Icon(Icons.alarm_off), + title: Text(i18n.gymModeExactAlarmMissing), + trailing: TextButton( + onPressed: () async { + await ref + .read(workoutNotificationServiceProvider) + .requestExactAlarms(); + ref.invalidate(exactAlarmsAllowedProvider); + }, + child: Text(i18n.gymModeExactAlarmAllow), ), ), - ], - ), + // The ongoing notification only exists on Android + if (isAndroid) + SwitchListTile( + key: const ValueKey('gym-mode-workout-notification'), + title: Text(i18n.gymModeWorkoutNotification), + subtitle: Text(i18n.gymModeWorkoutNotificationHelp), + value: gymState.showWorkoutNotification, + onChanged: (value) => gymNotifier.setShowWorkoutNotification(value), + ), + + const Divider(), + ListTile( + key: const ValueKey('gym-mode-log-scope'), + title: Text(i18n.gymModeLogScope), + subtitle: Text(i18n.gymModeLogScopeHelp), + trailing: DropdownButton( + key: const ValueKey('log-scope-dropdown'), + value: gymState.logScopeWeeks, + onChanged: (value) => gymNotifier.setLogScopeWeeks(value), + items: [ + DropdownMenuItem( + value: null, + child: Text(i18n.gymModeLogScopeCurrentRoutine), + ), + ...[8, 12, 25, 50].map( + (weeks) => DropdownMenuItem( + value: weeks, + child: Text(i18n.gymModeLogScopeWeeks(weeks)), + ), + ), + ], + ), + ), + SwitchListTile( + key: const ValueKey('gym-mode-distinct-logs'), + title: Text(i18n.gymModeDistinctLogs), + value: gymState.showDistinctLogs, + onChanged: (value) => gymNotifier.setShowDistinctLogs(value), + ), + ], ), - SwitchListTile( - key: const ValueKey('gym-mode-distinct-logs'), - title: Text(i18n.gymModeDistinctLogs), - value: gymState.showDistinctLogs, - onChanged: (value) => gymNotifier.setShowDistinctLogs(value), - ), - ], + ), ), ), ), + crossFadeState: _showOptions ? CrossFadeState.showSecond : CrossFadeState.showFirst, + duration: const Duration(milliseconds: 200), ), ), - crossFadeState: _showOptions ? CrossFadeState.showSecond : CrossFadeState.showFirst, - duration: const Duration(milliseconds: 200), - ), - ListTile( - key: const ValueKey('gym-mode-options-tile'), - title: Text(i18n.settingsTitle), - leading: const Icon(Icons.settings), - onTap: () => setState(() => _showOptions = !_showOptions), - ), - ], + ListTile( + key: const ValueKey('gym-mode-options-tile'), + title: Text(i18n.settingsTitle), + leading: const Icon(Icons.settings), + onTap: () => setState(() => _showOptions = !_showOptions), + ), + ], + ), ); } } @@ -274,50 +284,61 @@ class StartPage extends ConsumerWidget { showEndWorkoutButton: false, ), + // The opened options may take all of the room, e.g. with the keyboard up Expanded( - child: ListView( - children: [ - if (dayDataDisplay.day!.isSpecialType) - Center( - child: Padding( - padding: const EdgeInsets.all(15), - child: Text( - '${dayDataDisplay.day!.type.name.toUpperCase()}\n${dayDataDisplay.day!.type.i18Label(AppLocalizations.of(context))}', - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.headlineSmall, - ), + child: LayoutBuilder( + builder: (context, constraints) => Column( + children: [ + Expanded( + child: ListView( + children: [ + if (dayDataDisplay.day!.isSpecialType) + Center( + child: Padding( + padding: const EdgeInsets.all(15), + child: Text( + '${dayDataDisplay.day!.type.name.toUpperCase()}\n${dayDataDisplay.day!.type.i18Label(AppLocalizations.of(context))}', + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.headlineSmall, + ), + ), + ), + ...dayDataDisplay.slots + .expand((slot) => slot.setConfigs) + .fold>>({}, (acc, entry) { + acc.putIfAbsent(entry.exercise, () => []).add(entry.textReprWithType); + return acc; + }) + .entries + .map((entry) { + final exercise = entry.key; + return Column( + children: [ + ListTile( + leading: SizedBox( + width: 45, + child: ExerciseImageWidget(image: exercise.getMainImage), + ), + title: Text( + exercise + .getTranslation( + Localizations.localeOf(context).languageCode, + ) + .name, + ), + subtitle: Text(entry.value.toList().join('\n')), + ), + ], + ); + }), + ], ), ), - ...dayDataDisplay.slots - .expand((slot) => slot.setConfigs) - .fold>>({}, (acc, entry) { - acc.putIfAbsent(entry.exercise, () => []).add(entry.textReprWithType); - return acc; - }) - .entries - .map((entry) { - final exercise = entry.key; - return Column( - children: [ - ListTile( - leading: SizedBox( - width: 45, - child: ExerciseImageWidget(image: exercise.getMainImage), - ), - title: Text( - exercise - .getTranslation(Localizations.localeOf(context).languageCode) - .name, - ), - subtitle: Text(entry.value.toList().join('\n')), - ), - ], - ); - }), - ], + GymModeOptions(maxHeight: constraints.maxHeight), + ], + ), ), ), - const GymModeOptions(), FilledButton( child: Text(AppLocalizations.of(context).start), onPressed: () { diff --git a/lib/features/routines/widgets/gym_mode/timer.dart b/lib/features/routines/widgets/gym_mode/timer.dart index c76ef3ed4..0aefed621 100644 --- a/lib/features/routines/widgets/gym_mode/timer.dart +++ b/lib/features/routines/widgets/gym_mode/timer.dart @@ -1,13 +1,13 @@ /* * This file is part of wger Workout Manager . - * Copyright (C) 2020, 2025 wger Team + * Copyright (c) 2020 - 2026 wger Team * * wger Workout Manager is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * wger Workout Manager is distributed in the hope that it will be useful, + * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. diff --git a/test/features/routines/widgets/gym_mode/start_page_test.dart b/test/features/routines/widgets/gym_mode/start_page_test.dart index 17c0fe930..baa94d185 100644 --- a/test/features/routines/widgets/gym_mode/start_page_test.dart +++ b/test/features/routines/widgets/gym_mode/start_page_test.dart @@ -314,4 +314,26 @@ void main() { expect(hint, findsNothing); }); }); + testWidgets('The opened options fit a short screen, e.g. with the keyboard up', (tester) async { + tester.view.physicalSize = const Size(400, 480); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + + await tester.pumpWidget( + UncontrolledProviderScope( + container: container, + child: MaterialApp( + locale: const Locale('en'), + localizationsDelegates: appLocalizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: Scaffold(body: StartPage(PageController())), + ), + ), + ); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const ValueKey('gym-mode-options-tile'))); + await tester.pumpAndSettle(); + + expect(tester.takeException(), isNull); + }); }