diff --git a/lib/widgets/exercises/detail/aliases_section.dart b/lib/widgets/exercises/detail/aliases_section.dart new file mode 100644 index 000000000..41b80858b --- /dev/null +++ b/lib/widgets/exercises/detail/aliases_section.dart @@ -0,0 +1,47 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 - 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. + * + * 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. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:flutter/material.dart'; +import 'package:wger/l10n/generated/app_localizations.dart'; +import 'package:wger/models/exercises/translation.dart'; +import 'package:wger/widgets/core/core.dart'; + +class AliasesSection extends StatelessWidget { + final Translation translation; + + const AliasesSection({super.key, required this.translation}); + + @override + Widget build(BuildContext context) { + if (translation.aliases.isEmpty) { + return const SizedBox.shrink(); + } + + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + MutedText( + AppLocalizations.of(context).alsoKnownAs( + translation.aliases.map((e) => e.alias).toList().join(', '), + ), + ), + const SizedBox(height: 9), + ], + ); + } +} diff --git a/lib/widgets/exercises/detail/category_equipment_row.dart b/lib/widgets/exercises/detail/category_equipment_row.dart new file mode 100644 index 000000000..c9358905b --- /dev/null +++ b/lib/widgets/exercises/detail/category_equipment_row.dart @@ -0,0 +1,55 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 - 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. + * + * 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. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:flutter/material.dart'; +import 'package:wger/helpers/i18n.dart'; +import 'package:wger/models/exercises/exercise.dart'; + +class CategoryEquipmentRow extends StatelessWidget { + final Exercise exercise; + + const CategoryEquipmentRow({super.key, required this.exercise}); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + + return Row( + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 4), + child: Chip( + label: Text(getServerStringTranslation(exercise.category!.name, context)), + padding: EdgeInsets.zero, + backgroundColor: theme.splashColor, + ), + ), + ...exercise.equipment.map( + (e) => Padding( + padding: const EdgeInsets.symmetric(horizontal: 4), + child: Chip( + label: Text(getServerStringTranslation(e.name, context)), + padding: EdgeInsets.zero, + backgroundColor: theme.splashColor, + ), + ), + ), + ], + ); + } +} diff --git a/lib/widgets/exercises/detail/description_section.dart b/lib/widgets/exercises/detail/description_section.dart new file mode 100644 index 000000000..19f5fe15a --- /dev/null +++ b/lib/widgets/exercises/detail/description_section.dart @@ -0,0 +1,42 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 - 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. + * + * 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. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:flutter/material.dart'; +import 'package:flutter_html/flutter_html.dart'; +import 'package:wger/l10n/generated/app_localizations.dart'; +import 'package:wger/models/exercises/translation.dart'; + +class DescriptionSection extends StatelessWidget { + final Translation translation; + + const DescriptionSection({super.key, required this.translation}); + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + AppLocalizations.of(context).description, + style: Theme.of(context).textTheme.headlineSmall, + ), + Html(data: translation.description), + ], + ); + } +} diff --git a/lib/widgets/exercises/detail/images_section.dart b/lib/widgets/exercises/detail/images_section.dart new file mode 100644 index 000000000..be375d3e0 --- /dev/null +++ b/lib/widgets/exercises/detail/images_section.dart @@ -0,0 +1,42 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 - 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. + * + * 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. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:flutter/material.dart'; +import 'package:wger/models/exercises/exercise.dart'; +import 'package:wger/widgets/exercises/exercises.dart'; + +class ImagesSection extends StatelessWidget { + final Exercise exercise; + + const ImagesSection({super.key, required this.exercise}); + + @override + Widget build(BuildContext context) { + if (exercise.images.isEmpty) { + return const SizedBox.shrink(); + } + + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + CarouselImages(images: exercise.images), + const SizedBox(height: 9), + ], + ); + } +} diff --git a/lib/widgets/exercises/detail/muscles_section.dart b/lib/widgets/exercises/detail/muscles_section.dart new file mode 100644 index 000000000..ebceb3ac3 --- /dev/null +++ b/lib/widgets/exercises/detail/muscles_section.dart @@ -0,0 +1,83 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 - 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. + * + * 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. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:flutter/material.dart'; +import 'package:wger/l10n/generated/app_localizations.dart'; +import 'package:wger/models/exercises/exercise.dart'; +import 'package:wger/widgets/exercises/exercises.dart'; + +class MusclesSection extends StatelessWidget { + final Exercise exercise; + + const MusclesSection({super.key, required this.exercise}); + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + AppLocalizations.of(context).muscles, + style: Theme.of(context).textTheme.headlineSmall, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 9), + child: MuscleWidget( + muscles: exercise.muscles, + musclesSecondary: exercise.musclesSecondary, + isFront: true, + ), + ), + ), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 9), + child: MuscleWidget( + muscles: exercise.muscles, + musclesSecondary: exercise.musclesSecondary, + isFront: false, + ), + ), + ), + ], + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const MuscleColorHelper(main: true), + ...exercise.muscles.map((e) => Text(e.nameTranslated(context))), + ], + ), + const SizedBox(height: 9), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const MuscleColorHelper(main: false), + ...exercise.musclesSecondary.map((e) => Text(e.name)), + ], + ), + const SizedBox(height: 9), + ], + ); + } +} diff --git a/lib/widgets/exercises/detail/notes_section.dart b/lib/widgets/exercises/detail/notes_section.dart new file mode 100644 index 000000000..57fcbbd03 --- /dev/null +++ b/lib/widgets/exercises/detail/notes_section.dart @@ -0,0 +1,46 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 - 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. + * + * 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. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:flutter/material.dart'; +import 'package:wger/l10n/generated/app_localizations.dart'; +import 'package:wger/models/exercises/translation.dart'; + +class NotesSection extends StatelessWidget { + final Translation translation; + + const NotesSection({super.key, required this.translation}); + + @override + Widget build(BuildContext context) { + if (translation.notes.isEmpty) { + return const SizedBox.shrink(); + } + + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + AppLocalizations.of(context).notes, + style: Theme.of(context).textTheme.headlineSmall, + ), + ...translation.notes.map((e) => Text(e.comment)), + const SizedBox(height: 9), + ], + ); + } +} diff --git a/lib/widgets/exercises/detail/variations_section.dart b/lib/widgets/exercises/detail/variations_section.dart new file mode 100644 index 000000000..d4af42061 --- /dev/null +++ b/lib/widgets/exercises/detail/variations_section.dart @@ -0,0 +1,58 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 - 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. + * + * 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. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wger/l10n/generated/app_localizations.dart'; +import 'package:wger/models/exercises/exercise.dart'; +import 'package:wger/providers/exercises_notifier.dart'; +import 'package:wger/widgets/exercises/list_tile.dart'; + +class VariationsSection extends ConsumerWidget { + final Exercise exercise; + + const VariationsSection({super.key, required this.exercise}); + + @override + Widget build(BuildContext context, WidgetRef ref) { + if (exercise.variationGroup == null) { + return const SizedBox.shrink(); + } + + final exerciseState = ref.watch(exercisesProvider).value ?? const ExerciseState([]); + final variations = exerciseState.findByVariationGroup( + exercise.variationGroup, + exerciseIdToExclude: exercise.id, + ); + + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + AppLocalizations.of(context).variations, + style: Theme.of(context).textTheme.headlineSmall, + ), + if (variations.isEmpty) + const Text('-/-') + else + ...variations.map((e) => ExerciseListTile(exercise: e)), + const SizedBox(height: 9), + ], + ); + } +} diff --git a/lib/widgets/exercises/detail/videos_section.dart b/lib/widgets/exercises/detail/videos_section.dart new file mode 100644 index 000000000..227caa835 --- /dev/null +++ b/lib/widgets/exercises/detail/videos_section.dart @@ -0,0 +1,43 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 - 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. + * + * 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. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:flutter/material.dart'; +import 'package:wger/helpers/platform.dart'; +import 'package:wger/models/exercises/exercise.dart'; +import 'package:wger/widgets/exercises/videos.dart'; + +class VideosSection extends StatelessWidget { + final Exercise exercise; + + const VideosSection({super.key, required this.exercise}); + + @override + Widget build(BuildContext context) { + if (exercise.videos.isEmpty || isDesktop) { + return const SizedBox.shrink(); + } + + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ...exercise.videos.map((v) => ExerciseVideoWidget(video: v)), + const SizedBox(height: 9), + ], + ); + } +} diff --git a/lib/widgets/exercises/exercises.dart b/lib/widgets/exercises/exercises.dart index 617957355..115d4f7b6 100644 --- a/lib/widgets/exercises/exercises.dart +++ b/lib/widgets/exercises/exercises.dart @@ -18,35 +18,29 @@ import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_html/flutter_html.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:wger/helpers/consts.dart'; -import 'package:wger/helpers/i18n.dart'; -import 'package:wger/helpers/platform.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; import 'package:wger/models/exercises/exercise.dart'; import 'package:wger/models/exercises/image.dart'; import 'package:wger/models/exercises/muscle.dart'; -import 'package:wger/models/exercises/translation.dart'; -import 'package:wger/providers/exercises_notifier.dart'; -import 'package:wger/widgets/core/core.dart'; +import 'package:wger/widgets/exercises/detail/aliases_section.dart'; +import 'package:wger/widgets/exercises/detail/category_equipment_row.dart'; +import 'package:wger/widgets/exercises/detail/description_section.dart'; +import 'package:wger/widgets/exercises/detail/images_section.dart'; +import 'package:wger/widgets/exercises/detail/muscles_section.dart'; +import 'package:wger/widgets/exercises/detail/notes_section.dart'; +import 'package:wger/widgets/exercises/detail/variations_section.dart'; +import 'package:wger/widgets/exercises/detail/videos_section.dart'; import 'package:wger/widgets/exercises/images.dart'; -import 'package:wger/widgets/exercises/list_tile.dart'; -import 'package:wger/widgets/exercises/videos.dart'; -class ExerciseDetail extends ConsumerWidget { +class ExerciseDetail extends StatelessWidget { final Exercise _exercise; - static const PADDING = 9.0; - final CarouselController carouselController = CarouselController(); - ExerciseDetail(this._exercise); + const ExerciseDetail(this._exercise, {super.key}); @override - Widget build(BuildContext context, WidgetRef ref) { - // Reactive: rebuild when the catalogue updates. Empty fallback while - // the stream hasn't emitted yet. - final exerciseState = ref.watch(exercisesProvider).value ?? const ExerciseState([]); + Widget build(BuildContext context) { final translation = _exercise.getTranslation(Localizations.localeOf(context).languageCode); return SingleChildScrollView( @@ -54,234 +48,18 @@ class ExerciseDetail extends ConsumerWidget { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - // Category and equipment - getCategoriesAndEquipment(context), - - // Alternative names - ...getAliases(context, translation), - - // Videos - ...getVideos(), - - // Images - ...getImages(), - - // Description - ...getDescription(context, translation), - - // Notes - ...getNotes(context, translation), - - // Muscles - ...getMuscles(context), - - // Variants - ...getVariations(context, exerciseState), + CategoryEquipmentRow(exercise: _exercise), + AliasesSection(translation: translation), + VideosSection(exercise: _exercise), + ImagesSection(exercise: _exercise), + DescriptionSection(translation: translation), + NotesSection(translation: translation), + MusclesSection(exercise: _exercise), + VariationsSection(exercise: _exercise), ], ), ); } - - List getVariations(BuildContext context, ExerciseState exerciseState) { - final variations = exerciseState.findByVariationGroup( - _exercise.variationGroup, - exerciseIdToExclude: _exercise.id, - ); - - final List out = []; - if (_exercise.variationGroup == null) { - return out; - } - - out.add( - Text( - AppLocalizations.of(context).variations, - style: Theme.of(context).textTheme.headlineSmall, - ), - ); - for (final element in variations) { - out.add(ExerciseListTile(exercise: element)); - } - if (variations.isEmpty) { - out.add(const Text('-/-')); - } - - out.add(const SizedBox(height: PADDING)); - return out; - } - - List getNotes(BuildContext context, Translation translation) { - final List out = []; - if (translation.notes.isNotEmpty) { - out.add( - Text( - AppLocalizations.of(context).notes, - style: Theme.of(context).textTheme.headlineSmall, - ), - ); - for (final e in translation.notes) { - out.add(Text(e.comment)); - } - out.add(const SizedBox(height: PADDING)); - } - - return out; - } - - List getMuscles(BuildContext context) { - final List out = []; - out.add( - Text( - AppLocalizations.of(context).muscles, - style: Theme.of(context).textTheme.headlineSmall, - ), - ); - out.add( - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: PADDING), - child: MuscleWidget( - muscles: _exercise.muscles, - musclesSecondary: _exercise.musclesSecondary, - isFront: true, - ), - ), - ), - Expanded( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: PADDING), - child: MuscleWidget( - muscles: _exercise.muscles, - musclesSecondary: _exercise.musclesSecondary, - isFront: false, - ), - ), - ), - ], - ), - ); - - out.add( - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const MuscleColorHelper(main: true), - ..._exercise.muscles.map((e) => Text(e.nameTranslated(context))), - ], - ), - ); - out.add(const SizedBox(height: PADDING)); - out.add( - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const MuscleColorHelper(main: false), - ..._exercise.musclesSecondary.map((e) => Text(e.name)), - ], - ), - ); - - out.add(const SizedBox(height: PADDING)); - - return out; - } - - List getDescription(BuildContext context, Translation translation) { - final List out = []; - out.add( - Text( - AppLocalizations.of(context).description, - style: Theme.of(context).textTheme.headlineSmall, - ), - ); - out.add(Html(data: translation.description)); - - return out; - } - - List getImages() { - final List out = []; - if (_exercise.images.isNotEmpty) { - out.add( - CarouselImages( - images: _exercise.images, - ), - ); - - // out.add(ExerciseImageWidget( - // image: _exercise.getMainImage, - // height: 250, - // )); - out.add(const SizedBox(height: PADDING)); - } - - return out; - } - - Widget getCategoriesAndEquipment(BuildContext context) { - final List out = []; - final theme = Theme.of(context); - - out.add( - Padding( - padding: const EdgeInsets.symmetric(horizontal: 4), - child: Chip( - label: Text(getServerStringTranslation(_exercise.category!.name, context)), - padding: EdgeInsets.zero, - backgroundColor: theme.splashColor, - ), - ), - ); - if (_exercise.equipment.isNotEmpty) { - _exercise.equipment - .map( - (e) => Padding( - padding: const EdgeInsets.symmetric(horizontal: 4), - child: Chip( - label: Text(getServerStringTranslation(e.name, context)), - padding: EdgeInsets.zero, - backgroundColor: theme.splashColor, - ), - ), - ) - .forEach((element) => out.add(element)); - } - out.add(const SizedBox(height: PADDING)); - return Row(children: [...out]); - } - - List getVideos() { - // TODO: add carousel for the other videos - final List out = []; - if (_exercise.videos.isNotEmpty && !isDesktop) { - _exercise.videos.map((v) => ExerciseVideoWidget(video: v)).forEach((element) { - out.add(element); - }); - - out.add(const SizedBox(height: PADDING)); - } - return out; - } - - List getAliases(BuildContext context, Translation translation) { - final List out = []; - if (translation.aliases.isNotEmpty) { - out.add( - MutedText( - AppLocalizations.of(context).alsoKnownAs( - translation.aliases.map((e) => e.alias).toList().join(', '), - ), - ), - ); - out.add(const SizedBox(height: PADDING)); - } - - return out; - } } class MuscleColorHelper extends StatelessWidget {