diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index e5d6d0c2b..fcf51cd4a 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -92,6 +92,7 @@ jobs: dart manifest_generator.dart --meta ../flatpak_meta.json --github mkdir ../../flathub cp flatpak_generator_exports/de.wger.flutter.json ../../flathub + cp flatpak_generator_exports/flathub.json ../../flathub - name: Push updated config to flathub repository uses: cpina/github-action-push-to-another-repository@main @@ -120,7 +121,5 @@ jobs: git checkout -b release-${{ env.VERSION }} git add pubspec.yaml git commit -m "Bump version to $( flutter pub run cider version )" - git tag ${{ env.VERSION }} - git push origin ${{ env.VERSION }} git push origin --delete ${{ env.VERSION_V }} git push \ No newline at end of file diff --git a/AUTHORS.md b/AUTHORS.md index b617a4a7c..5372b1bc7 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -25,6 +25,7 @@ - Abhishek Saini - - Hanaa Allohibi - - Shey Alnasrawi - +- Costas Korai - ## Translators diff --git a/Gemfile.lock b/Gemfile.lock index e0b3d0764..b0b1c2f1d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -208,6 +208,7 @@ GEM PLATFORMS arm64-darwin-21 arm64-darwin-22 + arm64-darwin-23 x86_64-linux DEPENDENCIES diff --git a/ios/Flutter/AppFrameworkInfo.plist b/ios/Flutter/AppFrameworkInfo.plist index 4f8d4d245..8c6e56146 100644 --- a/ios/Flutter/AppFrameworkInfo.plist +++ b/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 11.0 + 12.0 diff --git a/ios/Podfile.lock b/ios/Podfile.lock index b8acaa9e4..0cdb23fc2 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -14,11 +14,29 @@ PODS: - Flutter - package_info_plus (0.4.5): - Flutter + - path_provider_foundation (0.0.1): + - Flutter + - FlutterMacOS - rive_common (0.0.1): - Flutter - shared_preferences_foundation (0.0.1): - Flutter - FlutterMacOS + - sqlite3 (3.45.0): + - sqlite3/common (= 3.45.0) + - sqlite3/common (3.45.0) + - sqlite3/fts5 (3.45.0): + - sqlite3/common + - sqlite3/perf-threadsafe (3.45.0): + - sqlite3/common + - sqlite3/rtree (3.45.0): + - sqlite3/common + - sqlite3_flutter_libs (0.0.1): + - Flutter + - sqlite3 (~> 3.45.0) + - sqlite3/fts5 + - sqlite3/perf-threadsafe + - sqlite3/rtree - url_launcher_ios (0.0.1): - Flutter - video_player_avfoundation (0.0.1): @@ -34,11 +52,17 @@ DEPENDENCIES: - image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`) - integration_test (from `.symlinks/plugins/integration_test/ios`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) + - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - rive_common (from `.symlinks/plugins/rive_common/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) + - sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/ios`) - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) - video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/darwin`) +SPEC REPOS: + trunk: + - sqlite3 + EXTERNAL SOURCES: camera_avfoundation: :path: ".symlinks/plugins/camera_avfoundation/ios" @@ -56,10 +80,14 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/integration_test/ios" package_info_plus: :path: ".symlinks/plugins/package_info_plus/ios" + path_provider_foundation: + :path: ".symlinks/plugins/path_provider_foundation/darwin" rive_common: :path: ".symlinks/plugins/rive_common/ios" shared_preferences_foundation: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" + sqlite3_flutter_libs: + :path: ".symlinks/plugins/sqlite3_flutter_libs/ios" url_launcher_ios: :path: ".symlinks/plugins/url_launcher_ios/ios" video_player_avfoundation: @@ -67,17 +95,20 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: camera_avfoundation: 3125e8cd1a4387f6f31c6c63abb8a55892a9eeeb - Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 + Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 flutter_barcode_scanner: 7a1144744c28dc0c57a8de7218ffe5ec59a9e4bf flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069 flutter_zxing: 19a866d17c8a87ee1026d68521c69d2f008635f6 image_picker_ios: 4a8aadfbb6dc30ad5141a2ce3832af9214a705b5 integration_test: 13825b8a9334a850581300559b8839134b124670 package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85 + path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 rive_common: 3a4c254c6e4db7e4b9e05daeb3d1f47ae4f7bf76 shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 - url_launcher_ios: 68d46cc9766d0c41dbdc884310529557e3cd7a86 - video_player_avfoundation: 8563f13d8fc8b2c29dc2d09e60b660e4e8128837 + sqlite3: f307b6291c4db7b5086c38d6237446b98a738581 + sqlite3_flutter_libs: aeb4d37509853dfa79d9b59386a2dac5dd079428 + url_launcher_ios: bf5ce03e0e2088bad9cc378ea97fa0ed5b49673b + video_player_avfoundation: e9e6f9cae7d7a6d9b43519b0aab382bca60fcfd1 PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 08905a67e..eaa06d26b 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -342,7 +342,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -428,7 +428,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -477,7 +477,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 5660e72dc..513b19daa 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -748,5 +748,45 @@ "description": "Generated entry for translation for server strings" }, "verify": "Verifizieren", - "@verify": {} + "@verify": {}, + "textPromptTitle": "Bereit zu starten?", + "@textPromptTitle": {}, + "settingsTitle": "Einstellung", + "@settingsTitle": {}, + "textPromptSubheading": "Drücken Sie die Aktionstaste, um zu beginnen", + "@textPromptSubheading": {}, + "max_reps": "Max. Wiederholungen", + "@max_reps": { + "description": "Generated entry for translation for server strings" + }, + "noMatchingExerciseFound": "Diese Übung wurde nicht gefunden", + "@noMatchingExerciseFound": { + "description": "Message returned if no exercises match the searched string" + }, + "aboutMastodonTitle": "Mastodon", + "@aboutMastodonTitle": { + "description": "Title for mastodon section in the about dialog" + }, + "plates": "Platten", + "@plates": { + "description": "Generated entry for translation for server strings" + }, + "aboutMastodonText": "Folgen Sie uns auf Mastodon für Updates und Neuigkeiten zum Projekt", + "@aboutMastodonText": { + "description": "Text for the mastodon section in the about dialog" + }, + "aboutDonateTitle": "Spende", + "@aboutDonateTitle": {}, + "aboutDonateText": "Kaufen Sie uns einen Kaffee, um das Projekt zu unterstützen, Serverkosten zu decken und uns weiterhin zu versorgen", + "@aboutDonateText": {}, + "settingsCacheTitle": "Zwischenspeicher", + "@settingsCacheTitle": {}, + "settingsCacheDescription": "Übungs-Zwischenspeicher", + "@settingsCacheDescription": {}, + "settingsCacheDeletedSnackbar": "Zwischenspeicher erfolgreich gelöscht", + "@settingsCacheDeletedSnackbar": {}, + "lb": "lb", + "@lb": { + "description": "Generated entry for translation for server strings" + } } diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 5ba87a4be..eb55d59e1 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -167,6 +167,7 @@ "@rirNotUsed": { "description": "Label used in RiR slider when the RiR value is not used/saved for the current setting or log" }, + "useMetric": "Use metric units for body weight", "weightUnit": "Weight unit", "@weightUnit": {}, "repetitionUnit": "Repetition unit", @@ -808,5 +809,10 @@ "none__bodyweight_exercise_": "none (bodyweight exercise)", "@none__bodyweight_exercise_": { "description": "Generated entry for translation for server strings" - } + }, + "log": "Log", + "@log": { + "description": "Log a specific meal (imperative form)" + }, + "done": "Done" } diff --git a/lib/l10n/app_hr.arb b/lib/l10n/app_hr.arb index 2b98be30f..8c6125fb6 100644 --- a/lib/l10n/app_hr.arb +++ b/lib/l10n/app_hr.arb @@ -835,5 +835,13 @@ "settingsCacheDescription": "Izvrši predmemoriju", "@settingsCacheDescription": {}, "settingsCacheDeletedSnackbar": "Predmemorija je uspješno izbrisana", - "@settingsCacheDeletedSnackbar": {} + "@settingsCacheDeletedSnackbar": {}, + "useMetric": "Koristi metričke jedinice za tjelesnu težinu", + "@useMetric": {}, + "log": "Zapiši", + "@log": { + "description": "Log a specific meal (imperative form)" + }, + "done": "Obavljeno", + "@done": {} } diff --git a/lib/models/nutrition/meal.dart b/lib/models/nutrition/meal.dart index a89330bb6..eff3f3d15 100644 --- a/lib/models/nutrition/meal.dart +++ b/lib/models/nutrition/meal.dart @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +import 'package:clock/clock.dart'; import 'package:flutter/material.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:wger/helpers/json.dart'; @@ -54,7 +55,7 @@ class Meal { this.mealItems = mealItems ?? []; - this.time = time ?? TimeOfDay.now(); + this.time = time ?? TimeOfDay.fromDateTime(clock.now()); this.name = name ?? ''; } diff --git a/lib/models/user/profile.dart b/lib/models/user/profile.dart index 5bb5335b5..ed7cb174a 100644 --- a/lib/models/user/profile.dart +++ b/lib/models/user/profile.dart @@ -31,6 +31,11 @@ class Profile { @JsonKey(required: true, name: 'is_trustworthy') bool isTrustworthy; + @JsonKey(required: true, name: 'weight_unit') + String weightUnitStr; + + bool get isMetric => weightUnitStr == 'kg'; + @JsonKey(required: true) String email; @@ -39,9 +44,11 @@ class Profile { required this.emailVerified, required this.isTrustworthy, required this.email, + required this.weightUnitStr, }); // Boilerplate factory Profile.fromJson(Map json) => _$ProfileFromJson(json); + Map toJson() => _$ProfileToJson(this); } diff --git a/lib/models/user/profile.g.dart b/lib/models/user/profile.g.dart index fc05b9cf2..1bc975c27 100644 --- a/lib/models/user/profile.g.dart +++ b/lib/models/user/profile.g.dart @@ -9,13 +9,14 @@ part of 'profile.dart'; Profile _$ProfileFromJson(Map json) { $checkKeys( json, - requiredKeys: const ['username', 'email_verified', 'is_trustworthy', 'email'], + requiredKeys: const ['username', 'email_verified', 'is_trustworthy', 'weight_unit', 'email'], ); return Profile( username: json['username'] as String, emailVerified: json['email_verified'] as bool, isTrustworthy: json['is_trustworthy'] as bool, email: json['email'] as String, + weightUnitStr: json['weight_unit'] as String, ); } @@ -23,5 +24,6 @@ Map _$ProfileToJson(Profile instance) => { 'username': instance.username, 'email_verified': instance.emailVerified, 'is_trustworthy': instance.isTrustworthy, + 'weight_unit': instance.weightUnitStr, 'email': instance.email, }; diff --git a/lib/screens/nutritional_plan_screen.dart b/lib/screens/nutritional_plan_screen.dart index c590464e5..f79dddc4a 100644 --- a/lib/screens/nutritional_plan_screen.dart +++ b/lib/screens/nutritional_plan_screen.dart @@ -107,6 +107,7 @@ class NutritionalPlanScreen extends StatelessWidget { ), ], flexibleSpace: FlexibleSpaceBar( + titlePadding: const EdgeInsets.fromLTRB(56, 0, 56, 16), title: Text( nutritionalPlan.getLabel(context), style: Theme.of(context).textTheme.titleLarge?.copyWith(color: appBarForeground), diff --git a/lib/screens/workout_plan_screen.dart b/lib/screens/workout_plan_screen.dart index 0fb013431..b0e175f15 100644 --- a/lib/screens/workout_plan_screen.dart +++ b/lib/screens/workout_plan_screen.dart @@ -82,6 +82,7 @@ class _WorkoutPlanScreenState extends State { iconTheme: const IconThemeData(color: appBarForeground), backgroundColor: wgerPrimaryColor, flexibleSpace: FlexibleSpaceBar( + titlePadding: const EdgeInsets.fromLTRB(56, 0, 56, 16), title: Text( workoutPlan.name, style: Theme.of(context).textTheme.titleLarge?.copyWith(color: appBarForeground), diff --git a/lib/widgets/dashboard/widgets.dart b/lib/widgets/dashboard/widgets.dart index 01699aa09..aedf5ef67 100644 --- a/lib/widgets/dashboard/widgets.dart +++ b/lib/widgets/dashboard/widgets.dart @@ -27,6 +27,7 @@ import 'package:wger/models/workouts/workout_plan.dart'; import 'package:wger/providers/body_weight.dart'; import 'package:wger/providers/measurement.dart'; import 'package:wger/providers/nutrition.dart'; +import 'package:wger/providers/user.dart'; import 'package:wger/providers/workout_plans.dart'; import 'package:wger/screens/form_screen.dart'; import 'package:wger/screens/gym_mode.dart'; @@ -146,14 +147,6 @@ class _DashboardNutritionWidgetState extends State { return out; } - Widget getTrailing() { - if (!_hasContent) { - return const Text(''); - } - - return _showDetail ? const Icon(Icons.expand_less) : const Icon(Icons.expand_more); - } - @override Widget build(BuildContext context) { return Card( @@ -174,7 +167,15 @@ class _DashboardNutritionWidgetState extends State { Icons.restaurant, color: Theme.of(context).textTheme.headlineSmall!.color, ), - trailing: getTrailing(), + trailing: _hasContent + ? Tooltip( + message: AppLocalizations.of(context).toggleDetails, + child: _showDetail + ? const Icon( + Icons.info, + ) + : const Icon(Icons.info_outline)) + : const SizedBox(), onTap: () { setState(() { _showDetail = !_showDetail; @@ -182,16 +183,18 @@ class _DashboardNutritionWidgetState extends State { }, ), if (_hasContent) - Column( - children: [ - ...getContent(), - Container( - padding: const EdgeInsets.all(15), - height: 180, - child: FlNutritionalPlanPieChartWidget(_plan!.nutritionalValues), - ) - ], - ) + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Column( + children: [ + ...getContent(), + Container( + padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), + height: 180, + child: FlNutritionalPlanPieChartWidget(_plan!.nutritionalValues), + ) + ], + )) else NothingFound( AppLocalizations.of(context).noNutritionalPlans, @@ -203,7 +206,17 @@ class _DashboardNutritionWidgetState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ TextButton( - child: Text(AppLocalizations.of(context).logIngredient), + child: Text(AppLocalizations.of(context).goToDetailPage), + onPressed: () { + Navigator.of(context) + .pushNamed(NutritionalPlanScreen.routeName, arguments: _plan); + }, + ), + IconButton( + icon: const Icon( + Icons.history_edu, + ), + tooltip: AppLocalizations.of(context).logIngredient, onPressed: () { Navigator.pushNamed( context, @@ -216,13 +229,6 @@ class _DashboardNutritionWidgetState extends State { ); }, ), - TextButton( - child: Text(AppLocalizations.of(context).goToDetailPage), - onPressed: () { - Navigator.of(context) - .pushNamed(NutritionalPlanScreen.routeName, arguments: _plan); - }, - ), ], ), ], @@ -241,6 +247,7 @@ class _DashboardWeightWidgetState extends State { @override Widget build(BuildContext context) { + final profile = context.read().profile; weightEntriesData = Provider.of(context, listen: false); return Consumer( @@ -265,9 +272,13 @@ class _DashboardWeightWidgetState extends State { children: [ SizedBox( height: 200, - child: MeasurementChartWidgetFl(weightEntriesData.items - .map((e) => MeasurementChartEntry(e.weight, e.date)) - .toList()), + child: MeasurementChartWidgetFl( + weightEntriesData.items + .map((e) => MeasurementChartEntry(e.weight, e.date)) + .toList(), + unit: profile!.isMetric + ? AppLocalizations.of(context).kg + : AppLocalizations.of(context).lb), ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -441,14 +452,6 @@ class _DashboardWorkoutWidgetState extends State { _hasContent = _workoutPlan != null; } - Widget getTrailing() { - if (!_hasContent) { - return const Text(''); - } - - return _showDetail ? const Icon(Icons.expand_less) : const Icon(Icons.expand_more); - } - List getContent() { final List out = []; @@ -540,7 +543,15 @@ class _DashboardWorkoutWidgetState extends State { Icons.fitness_center, color: Theme.of(context).textTheme.headlineSmall!.color, ), - trailing: getTrailing(), + trailing: _hasContent + ? Tooltip( + message: AppLocalizations.of(context).toggleDetails, + child: _showDetail + ? const Icon( + Icons.info, + ) + : const Icon(Icons.info_outline)) + : const SizedBox(), onTap: () { setState(() { _showDetail = !_showDetail; @@ -548,8 +559,8 @@ class _DashboardWorkoutWidgetState extends State { }, ), if (_hasContent) - Container( - padding: const EdgeInsets.only(left: 10), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), child: Column( children: [ ...getContent(), @@ -564,7 +575,7 @@ class _DashboardWorkoutWidgetState extends State { ), if (_hasContent) Row( - mainAxisAlignment: MainAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.start, children: [ TextButton( child: Text(AppLocalizations.of(context).goToDetailPage), diff --git a/lib/widgets/measurements/entries.dart b/lib/widgets/measurements/entries.dart index c3cf83379..b37eea4ca 100644 --- a/lib/widgets/measurements/entries.dart +++ b/lib/widgets/measurements/entries.dart @@ -23,7 +23,6 @@ import 'package:provider/provider.dart'; import 'package:wger/models/measurements/measurement_category.dart'; import 'package:wger/providers/measurement.dart'; import 'package:wger/screens/form_screen.dart'; -import 'package:wger/theme/theme.dart'; import 'package:wger/widgets/measurements/charts.dart'; import 'forms.dart'; @@ -52,72 +51,46 @@ class EntriesList extends StatelessWidget { final currentEntry = _category.entries[index]; final provider = Provider.of(context, listen: false); - return Dismissible( - key: Key(currentEntry.id.toString()), - onDismissed: (direction) { - if (direction == DismissDirection.endToStart) { - // Delete entry from DB - provider.deleteEntry(currentEntry.id!, currentEntry.category); + return Card( + child: ListTile( + title: Text('${currentEntry.value} ${_category.unit}'), + subtitle: Text( + DateFormat.yMd(Localizations.localeOf(context).languageCode) + .format(currentEntry.date), + ), + trailing: PopupMenuButton( + itemBuilder: (BuildContext context) { + return [ + PopupMenuItem( + child: Text(AppLocalizations.of(context).edit), + onTap: () => Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).edit, + MeasurementEntryForm(currentEntry.category, currentEntry), + ), + )), + PopupMenuItem( + child: Text(AppLocalizations.of(context).delete), + onTap: () async { + // Delete entry from DB + await provider.deleteEntry(currentEntry.id!, currentEntry.category); - // and inform the user - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context).successfullyDeleted, - textAlign: TextAlign.center, - ), - ), - ); - } - }, - confirmDismiss: (direction) async { - // Edit entry - if (direction == DismissDirection.startToEnd) { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).edit, - MeasurementEntryForm(currentEntry.category, currentEntry), - ), - ); - return false; - } - return true; - }, - secondaryBackground: Container( - color: Theme.of(context).colorScheme.error, - alignment: Alignment.centerRight, - padding: const EdgeInsets.only(right: 20), - margin: const EdgeInsets.symmetric( - horizontal: 4, - vertical: 4, - ), - child: const Icon( - Icons.delete, - color: Colors.white, - ), - ), - background: Container( - color: wgerPrimaryButtonColor, - alignment: Alignment.centerLeft, - padding: const EdgeInsets.only(left: 20), - margin: const EdgeInsets.symmetric( - horizontal: 4, - vertical: 4, - ), - child: const Icon( - Icons.edit, - color: Colors.white, - ), - ), - child: Card( - child: ListTile( - title: Text('${currentEntry.value} ${_category.unit}'), - subtitle: Text( - DateFormat.yMd(Localizations.localeOf(context).languageCode) - .format(currentEntry.date), - ), + // and inform the user + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of(context).successfullyDeleted, + textAlign: TextAlign.center, + ), + ), + ); + } + }) + ]; + }, ), ), ); diff --git a/lib/widgets/nutrition/meal.dart b/lib/widgets/nutrition/meal.dart index 381ef006c..a9d71c132 100644 --- a/lib/widgets/nutrition/meal.dart +++ b/lib/widgets/nutrition/meal.dart @@ -43,11 +43,18 @@ class MealWidget extends StatefulWidget { } class _MealWidgetState extends State { - bool _expanded = false; + bool _showingDetails = false; + bool _editing = false; - void _toggleExpanded() { + void _toggleEditing() { setState(() { - _expanded = !_expanded; + _editing = !_editing; + }); + } + + void _toggleDetails() { + setState(() { + _showingDetails = !_showingDetails; }); } @@ -57,85 +64,72 @@ class _MealWidgetState extends State { padding: const EdgeInsets.all(3), child: Card( child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - DismissibleMealHeader(_expanded, _toggleExpanded, meal: widget._meal), - if (_expanded) - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - IconButton( - onPressed: () { - // Delete the meal - Provider.of(context, listen: false) - .deleteMeal(widget._meal); - - // and inform the user - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context).successfullyDeleted, - textAlign: TextAlign.center, - ), - ), - ); - }, - icon: const Icon(Icons.delete), - ), - if (widget._meal.mealItems.isNotEmpty) - Ink( - decoration: ShapeDecoration( - color: Theme.of(context).primaryColor, //wgerPrimaryButtonColor, - shape: const CircleBorder(), - ), - child: IconButton( - icon: const Icon(Icons.history_edu), - color: Colors.white, + MealHeader( + editing: _editing, + toggleEditing: _toggleEditing, + showingDetails: _showingDetails, + toggleDetails: _toggleDetails, + meal: widget._meal), + if (_editing) + Padding( + padding: const EdgeInsets.symmetric(vertical: 8), + child: Wrap( + spacing: 8, + children: [ + TextButton.icon( + icon: const Icon(Icons.add), + label: Text(AppLocalizations.of(context).addIngredient), onPressed: () { - Provider.of(context, listen: false) - .logMealToDiary(widget._meal); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context).mealLogged, - textAlign: TextAlign.center, - ), + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).addIngredient, + MealItemForm(widget._meal, widget._listMealItems), + hasListView: true, ), ); }, ), - ), - IconButton( - onPressed: () { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).edit, - MealForm(widget._meal.planId, widget._meal), - ), - ); - }, - icon: const Icon(Icons.edit), - ), - ], - ), - if (_expanded) const Divider(), - ...widget._meal.mealItems.map((item) => MealItemWidget(item, _expanded)), - OutlinedButton( - child: Text(AppLocalizations.of(context).addIngredient), - onPressed: () { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).addIngredient, - MealItemForm(widget._meal, widget._listMealItems), - hasListView: true, - ), - ); - }, - ), + TextButton.icon( + label: Text(AppLocalizations.of(context).edit), + onPressed: () { + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).edit, + MealForm(widget._meal.planId, widget._meal), + ), + ); + }, + icon: const Icon(Icons.timer), + ), + TextButton.icon( + onPressed: () { + // Delete the meal + Provider.of(context, listen: false) + .deleteMeal(widget._meal); + + // and inform the user + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of(context).successfullyDeleted, + textAlign: TextAlign.center, + ), + ), + ); + }, + label: Text(AppLocalizations.of(context).delete), + icon: const Icon(Icons.delete)), + ], + )), + const Divider(), + ...widget._meal.mealItems + .map((item) => MealItemWidget(item, _showingDetails, _editing)), ], ), ), @@ -144,10 +138,11 @@ class _MealWidgetState extends State { } class MealItemWidget extends StatelessWidget { - final bool _expanded; + final bool _editing; + final bool _showingDetails; final MealItem _item; - const MealItemWidget(this._item, this._expanded); + const MealItemWidget(this._item, this._showingDetails, this._editing); @override Widget build(BuildContext context) { @@ -180,11 +175,12 @@ class MealItemWidget extends StatelessWidget { ), subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, - children: [if (_expanded) ...getMutedNutritionalValues(values, context)], + children: [if (_showingDetails) ...getMutedNutritionalValues(values, context)], ), - trailing: _expanded + trailing: _editing ? IconButton( icon: const Icon(Icons.delete), + tooltip: AppLocalizations.of(context).delete, iconSize: ICON_SIZE_SMALL, onPressed: () { // Delete the meal item @@ -205,87 +201,95 @@ class MealItemWidget extends StatelessWidget { } } -class DismissibleMealHeader extends StatelessWidget { - final bool _expanded; - final Function _toggle; +class MealHeader extends StatelessWidget { + final bool _editing; + final bool _showingDetails; + final Function _toggleEditing; + final Function _toggleDetails; - const DismissibleMealHeader( - this._expanded, - this._toggle, { + const MealHeader({ required Meal meal, - }) : _meal = meal; + required bool editing, + required Function toggleEditing, + required bool showingDetails, + required Function toggleDetails, + }) : _toggleDetails = toggleDetails, + _toggleEditing = toggleEditing, + _showingDetails = showingDetails, + _editing = editing, + _meal = meal; final Meal _meal; @override Widget build(BuildContext context) { - return Dismissible( - key: Key(_meal.id.toString()), - direction: DismissDirection.startToEnd, - background: Container( - color: Theme.of(context).primaryColor, //wgerPrimaryButtonColor, - alignment: Alignment.centerLeft, - padding: const EdgeInsets.only(left: 10), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), + title: Row(children: [ + Expanded( + child: (_meal.name != '') + ? Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + _meal.name, + style: Theme.of(context).textTheme.titleMedium, + ), + Text( + _meal.time!.format(context), + style: Theme.of(context).textTheme.headlineSmall, + ) + ], + ) + : Text( + _meal.time!.format(context), + style: Theme.of(context).textTheme.headlineSmall, + ), + ), Text( - AppLocalizations.of(context).logMeal, - style: const TextStyle(color: Colors.white), + AppLocalizations.of(context).log, + style: Theme.of(context) + .textTheme + .labelLarge + ?.copyWith(color: Theme.of(context).colorScheme.primary), ), - const Icon( - Icons.history_edu, - color: Colors.white, + const SizedBox(width: 26), + const SizedBox(height: 40, width: 1, child: VerticalDivider()), + ]), + trailing: Row(mainAxisSize: MainAxisSize.min, children: [ + IconButton( + icon: _showingDetails ? const Icon(Icons.info) : const Icon(Icons.info_outline), + onPressed: () { + _toggleDetails(); + }, + tooltip: AppLocalizations.of(context).toggleDetails, ), - ], - ), - ), - confirmDismiss: (direction) async { - // Delete - if (direction == DismissDirection.startToEnd) { - Provider.of(context, listen: false).logMealToDiary(_meal); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context).mealLogged, - textAlign: TextAlign.center, - ), - ), - ); - } - return false; - }, - child: Container( - padding: const EdgeInsets.all(10), - decoration: BoxDecoration(color: Theme.of(context).colorScheme.inversePrimary), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (_meal.name != '') - Text( - _meal.name, - style: Theme.of(context).textTheme.headlineSmall, - ), - Row( - children: [ - Expanded( - child: Text( - _meal.time!.format(context), - style: Theme.of(context).textTheme.headlineSmall, - ), + const SizedBox(width: 5), + IconButton( + icon: _editing ? const Icon(Icons.done) : const Icon(Icons.edit), + tooltip: + _editing ? AppLocalizations.of(context).done : AppLocalizations.of(context).edit, + onPressed: () { + _toggleEditing(); + }, + ) + ]), + onTap: () { + Provider.of(context, listen: false).logMealToDiary(_meal); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of(context).mealLogged, + textAlign: TextAlign.center, ), - IconButton( - visualDensity: VisualDensity.compact, - icon: _expanded ? const Icon(Icons.unfold_less) : const Icon(Icons.unfold_more), - onPressed: () { - _toggle(); - }, - ), - ], - ), - ], + ), + ); + }, ), - ), + ], ); } } diff --git a/lib/widgets/nutrition/nutritional_diary_detail.dart b/lib/widgets/nutrition/nutritional_diary_detail.dart index af07c2911..d1080e4fd 100644 --- a/lib/widgets/nutrition/nutritional_diary_detail.dart +++ b/lib/widgets/nutrition/nutritional_diary_detail.dart @@ -195,6 +195,7 @@ class NutritionalDiaryDetailWidget extends StatelessWidget { ), ), IconButton( + tooltip: AppLocalizations.of(context).delete, onPressed: () { Provider.of(context, listen: false) .deleteLog(log.id!, _nutritionalPlan.id!); diff --git a/lib/widgets/nutrition/nutritional_plans_list.dart b/lib/widgets/nutrition/nutritional_plans_list.dart index 58b112108..3377a6c93 100644 --- a/lib/widgets/nutrition/nutritional_plans_list.dart +++ b/lib/widgets/nutrition/nutritional_plans_list.dart @@ -39,78 +39,70 @@ class NutritionalPlansList extends StatelessWidget { itemCount: _nutritionProvider.items.length, itemBuilder: (context, index) { final currentPlan = _nutritionProvider.items[index]; - return Dismissible( - key: Key(currentPlan.id.toString()), - confirmDismiss: (direction) async { - // Delete workout from DB - final bool? res = await showDialog( - context: context, - builder: (BuildContext contextDialog) { - return AlertDialog( - content: Text( - AppLocalizations.of(context).confirmDelete(currentPlan.description), - ), - actions: [ - TextButton( - child: Text(MaterialLocalizations.of(context).cancelButtonLabel), - onPressed: () => Navigator.of(contextDialog).pop(), - ), - TextButton( - child: Text( - AppLocalizations.of(context).delete, - style: TextStyle(color: Theme.of(context).colorScheme.error), - ), - onPressed: () { - // Confirmed, delete the workout - _nutritionProvider.deletePlan(currentPlan.id!); - - // Close the popup - Navigator.of(contextDialog).pop(); - - // and inform the user - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context).successfullyDeleted, - textAlign: TextAlign.center, - ), + return Card( + child: ListTile( + onTap: () { + Navigator.of(context).pushNamed( + NutritionalPlanScreen.routeName, + arguments: currentPlan, + ); + }, + title: Text(currentPlan.getLabel(context)), + subtitle: Text( + DateFormat.yMd(Localizations.localeOf(context).languageCode) + .format(currentPlan.creationDate), + ), + trailing: Row(mainAxisSize: MainAxisSize.min, children: [ + const VerticalDivider(), + IconButton( + icon: const Icon(Icons.delete), + tooltip: AppLocalizations.of(context).delete, + onPressed: () async { + // Delete workout from DB + await showDialog( + context: context, + builder: (BuildContext contextDialog) { + return AlertDialog( + content: Text( + AppLocalizations.of(context) + .confirmDelete(currentPlan.description), + ), + actions: [ + TextButton( + child: + Text(MaterialLocalizations.of(context).cancelButtonLabel), + onPressed: () => Navigator.of(contextDialog).pop(), ), - ); - }, - ), - ], - ); - }); - return res; - }, - background: Container( - color: Theme.of(context).colorScheme.error, - alignment: Alignment.centerRight, - padding: const EdgeInsets.only(right: 20), - margin: const EdgeInsets.symmetric( - horizontal: 4, - vertical: 4, - ), - child: const Icon( - Icons.delete, - color: Colors.white, - ), - ), - direction: DismissDirection.endToStart, - child: Card( - child: ListTile( - onTap: () { - Navigator.of(context).pushNamed( - NutritionalPlanScreen.routeName, - arguments: currentPlan, - ); - }, - title: Text(currentPlan.getLabel(context)), - subtitle: Text( - DateFormat.yMd(Localizations.localeOf(context).languageCode) - .format(currentPlan.creationDate), - ), - ), + TextButton( + child: Text( + AppLocalizations.of(context).delete, + style: + TextStyle(color: Theme.of(context).colorScheme.error), + ), + onPressed: () { + // Confirmed, delete the workout + _nutritionProvider.deletePlan(currentPlan.id!); + + // Close the popup + Navigator.of(contextDialog).pop(); + + // and inform the user + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of(context).successfullyDeleted, + textAlign: TextAlign.center, + ), + ), + ); + }, + ), + ], + ); + }); + }, + ) + ]), ), ); }, diff --git a/lib/widgets/user/forms.dart b/lib/widgets/user/forms.dart index 87907f8ed..5f4a58cdc 100644 --- a/lib/widgets/user/forms.dart +++ b/lib/widgets/user/forms.dart @@ -23,14 +23,26 @@ import 'package:wger/models/user/profile.dart'; import 'package:wger/providers/user.dart'; import 'package:wger/theme/theme.dart'; -class UserProfileForm extends StatelessWidget { +class UserProfileForm extends StatefulWidget { late final Profile _profile; - final _form = GlobalKey(); - final emailController = TextEditingController(); UserProfileForm(Profile profile) { _profile = profile; - emailController.text = _profile.email; + } + + @override + State createState() => _UserProfileFormState(); +} + +class _UserProfileFormState extends State { + final _form = GlobalKey(); + + final emailController = TextEditingController(); + + @override + void initState() { + super.initState(); + emailController.text = widget._profile.email; } @override @@ -42,16 +54,29 @@ class UserProfileForm extends StatelessWidget { ListTile( leading: const Icon(Icons.person, color: wgerPrimaryColor), title: Text(AppLocalizations.of(context).username), - subtitle: Text(_profile.username), + subtitle: Text(widget._profile.username), + ), + SwitchListTile( + title: Text(AppLocalizations.of(context).useMetric), + subtitle: Text(widget._profile.weightUnitStr), + value: widget._profile.isMetric, + onChanged: (_) { + setState(() { + widget._profile.weightUnitStr = widget._profile.isMetric + ? AppLocalizations.of(context).lb + : AppLocalizations.of(context).kg; + }); + }, + dense: true, ), ListTile( leading: const Icon(Icons.email_rounded, color: wgerPrimaryColor), title: TextFormField( decoration: InputDecoration( - labelText: _profile.emailVerified + labelText: widget._profile.emailVerified ? AppLocalizations.of(context).verifiedEmail : AppLocalizations.of(context).unVerifiedEmail, - suffixIcon: _profile.emailVerified + suffixIcon: widget._profile.emailVerified ? const Icon( Icons.check_circle, color: Colors.green, @@ -60,7 +85,7 @@ class UserProfileForm extends StatelessWidget { controller: emailController, keyboardType: TextInputType.emailAddress, onSaved: (newValue) { - _profile.email = newValue!; + widget._profile.email = newValue!; }, validator: (value) { if (value!.isNotEmpty && !value.contains('@')) { @@ -70,11 +95,11 @@ class UserProfileForm extends StatelessWidget { }, ), ), - if (!_profile.emailVerified) + if (!widget._profile.emailVerified) OutlinedButton( onPressed: () async { // Email is already verified - if (_profile.emailVerified) { + if (widget._profile.emailVerified) { return; } @@ -83,7 +108,7 @@ class UserProfileForm extends StatelessWidget { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( - AppLocalizations.of(context).verifiedEmailInfo(_profile.email), + AppLocalizations.of(context).verifiedEmailInfo(widget._profile.email), ), ), ); @@ -91,9 +116,6 @@ class UserProfileForm extends StatelessWidget { child: Text(AppLocalizations.of(context).verify), ), ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: wgerPrimaryButtonColor, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(50))), onPressed: () async { // Validate and save the current values to the weightEntry final isValid = _form.currentState!.validate(); diff --git a/lib/widgets/weight/entries_list.dart b/lib/widgets/weight/entries_list.dart index 8377ec5b6..573af7b34 100644 --- a/lib/widgets/weight/entries_list.dart +++ b/lib/widgets/weight/entries_list.dart @@ -21,6 +21,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import 'package:wger/providers/body_weight.dart'; +import 'package:wger/providers/user.dart'; import 'package:wger/screens/form_screen.dart'; import 'package:wger/screens/measurement_categories_screen.dart'; import 'package:wger/widgets/measurements/charts.dart'; @@ -29,6 +30,7 @@ import 'package:wger/widgets/weight/forms.dart'; class WeightEntriesList extends StatelessWidget { @override Widget build(BuildContext context) { + final profile = context.read().profile; final weightProvider = Provider.of(context, listen: false); return Column( @@ -37,7 +39,11 @@ class WeightEntriesList extends StatelessWidget { padding: const EdgeInsets.all(15), height: 220, child: MeasurementChartWidgetFl( - weightProvider.items.map((e) => MeasurementChartEntry(e.weight, e.date)).toList()), + weightProvider.items.map((e) => MeasurementChartEntry(e.weight, e.date)).toList(), + unit: profile!.isMetric + ? AppLocalizations.of(context).kg + : AppLocalizations.of(context).lb, + ), ), TextButton( onPressed: () => Navigator.pushNamed( @@ -60,72 +66,47 @@ class WeightEntriesList extends StatelessWidget { itemCount: weightProvider.items.length, itemBuilder: (context, index) { final currentEntry = weightProvider.items[index]; - return Dismissible( - key: Key(currentEntry.id.toString()), - onDismissed: (direction) { - if (direction == DismissDirection.endToStart) { - // Delete entry from DB - weightProvider.deleteEntry(currentEntry.id!); + return Card( + child: ListTile( + title: Text('${currentEntry.weight} kg'), + subtitle: Text( + DateFormat.yMd(Localizations.localeOf(context).languageCode) + .format(currentEntry.date), + ), + trailing: PopupMenuButton( + itemBuilder: (BuildContext context) { + return [ + PopupMenuItem( + child: Text(AppLocalizations.of(context).edit), + onTap: () => Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).edit, + WeightForm(currentEntry), + ), + )), + PopupMenuItem( + child: Text(AppLocalizations.of(context).delete), + onTap: () async { + // Delete entry from DB + await weightProvider.deleteEntry(currentEntry.id!); - // and inform the user - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context).successfullyDeleted, - textAlign: TextAlign.center, - ), - ), - ); - } - }, - confirmDismiss: (direction) async { - // Edit entry - if (direction == DismissDirection.startToEnd) { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).edit, - WeightForm(currentEntry), - ), - ); - return false; - } - return true; - }, - secondaryBackground: Container( - color: Theme.of(context).colorScheme.error, - alignment: Alignment.centerRight, - padding: const EdgeInsets.only(right: 20), - margin: const EdgeInsets.symmetric( - horizontal: 4, - vertical: 4, - ), - child: const Icon( - Icons.delete, - color: Colors.white, - ), - ), - background: Container( - // color: wgerPrimaryButtonColor, - alignment: Alignment.centerLeft, - padding: const EdgeInsets.only(left: 20), - margin: const EdgeInsets.symmetric( - horizontal: 4, - vertical: 4, - ), - child: const Icon( - Icons.edit, - color: Colors.white, - ), - ), - child: Card( - child: ListTile( - title: Text('${currentEntry.weight} kg'), - subtitle: Text( - DateFormat.yMd(Localizations.localeOf(context).languageCode) - .format(currentEntry.date), - ), + // and inform the user + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of(context).successfullyDeleted, + textAlign: TextAlign.center, + ), + ), + ); + } + }, + ) + ]; + }, ), ), ); diff --git a/lib/widgets/workouts/day.dart b/lib/widgets/workouts/day.dart index d73235c09..30df13594 100644 --- a/lib/widgets/workouts/day.dart +++ b/lib/widgets/workouts/day.dart @@ -97,7 +97,7 @@ class WorkoutDayWidget extends StatefulWidget { } class _WorkoutDayWidgetState extends State { - bool _expanded = false; + bool _editing = false; late List _sets; @override @@ -109,20 +109,21 @@ class _WorkoutDayWidgetState extends State { void _toggleExpanded() { setState(() { - _expanded = !_expanded; + _editing = !_editing; }); } Widget getSetRow(Set set, int index) { return Row( key: ValueKey(set.id), - crossAxisAlignment: CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, children: [ - if (_expanded) + if (_editing) IconButton( visualDensity: VisualDensity.compact, icon: const Icon(Icons.delete), iconSize: ICON_SIZE_SMALL, + tooltip: AppLocalizations.of(context).delete, onPressed: () { Provider.of(context, listen: false).deleteSet(set); }, @@ -135,7 +136,7 @@ class _WorkoutDayWidgetState extends State { (setting) => SettingWidget( set: set, setting: setting, - expanded: _expanded, + expanded: _editing, toggle: _toggleExpanded, ), ), @@ -143,7 +144,7 @@ class _WorkoutDayWidgetState extends State { ], ), ), - if (_expanded) + if (_editing) ReorderableDragStartListener( index: index, child: const IconButton( @@ -162,62 +163,65 @@ class _WorkoutDayWidgetState extends State { child: Card( margin: EdgeInsets.zero, child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - DayHeaderDismissible( + DayHeader( day: widget._day, - expanded: _expanded, + expanded: _editing, toggle: _toggleExpanded, ), - if (_expanded) - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - IconButton( - onPressed: () { - Provider.of(context, listen: false).deleteDay( - widget._day, - ); - }, - icon: const Icon(Icons.delete), - ), - if (widget._day.sets.isNotEmpty) - Ink( - decoration: ShapeDecoration( - color: Theme.of(context).primaryColor, - shape: const CircleBorder(), - ), - child: IconButton( - icon: const Icon(Icons.play_arrow), - color: Colors.white, + if (_editing) + Padding( + padding: const EdgeInsets.symmetric(vertical: 8), + child: Wrap( + spacing: 8, + children: [ + TextButton.icon( + label: Text(AppLocalizations.of(context).addSet), + icon: const Icon(Icons.add), onPressed: () { - Navigator.of(context).pushNamed( - GymModeScreen.routeName, - arguments: widget._day, + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).newSet, + SetFormWidget(widget._day), + hasListView: true, + padding: EdgeInsets.zero, + ), ); }, ), - ), - IconButton( - onPressed: () { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).edit, - DayFormWidget( - Provider.of(context, listen: false) - .findById(widget._day.workoutId), - widget._day), - hasListView: true, - ), - ); - }, - icon: const Icon(Icons.edit), - ), - ], - ), - if (_expanded) const Divider(), + TextButton.icon( + icon: const Icon(Icons.calendar_month), + label: Text(AppLocalizations.of(context).edit), + onPressed: () { + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).edit, + DayFormWidget( + Provider.of(context, listen: false) + .findById(widget._day.workoutId), + widget._day), + hasListView: true, + ), + ); + }, + ), + TextButton.icon( + icon: const Icon(Icons.delete), + label: Text(AppLocalizations.of(context).delete), + onPressed: () { + Provider.of(context, listen: false).deleteDay( + widget._day, + ); + }, + ), + ], + )), + const Divider(), ReorderableListView( physics: const NeverScrollableScrollPhysics(), shrinkWrap: true, @@ -240,21 +244,6 @@ class _WorkoutDayWidgetState extends State { for (var i = 0; i < widget._day.sets.length; i++) getSetRow(widget._day.sets[i], i), ], ), - OutlinedButton( - child: Text(AppLocalizations.of(context).addSet), - onPressed: () { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).newSet, - SetFormWidget(widget._day), - hasListView: true, - padding: EdgeInsets.zero, - ), - ); - }, - ), ], ), ), @@ -262,77 +251,48 @@ class _WorkoutDayWidgetState extends State { } } -class DayHeaderDismissible extends StatelessWidget { +class DayHeader extends StatelessWidget { final Day _day; - final bool _expanded; + final bool _editing; final Function _toggle; - const DayHeaderDismissible({ + const DayHeader({ required Day day, required bool expanded, required Function toggle, }) : _day = day, - _expanded = expanded, + _editing = expanded, _toggle = toggle; @override Widget build(BuildContext context) { - return Dismissible( - key: Key(_day.id.toString()), - direction: DismissDirection.startToEnd, - background: Container( - color: Theme.of(context).primaryColor, - alignment: Alignment.centerLeft, - padding: const EdgeInsets.only(left: 10), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - AppLocalizations.of(context).gymMode, - style: const TextStyle(color: Colors.white), - ), - const Icon( - Icons.play_arrow, - color: Colors.white, - ), - ], - ), + return ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), + title: Text( + _day.description, + style: Theme.of(context).textTheme.headlineSmall, + overflow: TextOverflow.ellipsis, ), - confirmDismiss: (direction) async { - // Delete day - if (direction == DismissDirection.startToEnd) { - Navigator.of(context).pushNamed(GymModeScreen.routeName, arguments: _day); - } - return false; + subtitle: Text(_day.getDaysTextTranslated(Localizations.localeOf(context).languageCode)), + leading: const Icon(Icons.play_arrow), + minLeadingWidth: 8, + trailing: Row(mainAxisSize: MainAxisSize.min, children: [ + const SizedBox(height: 40, width: 1, child: VerticalDivider()), + const SizedBox(width: 10), + IconButton( + icon: _editing ? const Icon(Icons.done) : const Icon(Icons.edit), + tooltip: _editing ? AppLocalizations.of(context).done : AppLocalizations.of(context).edit, + onPressed: () { + _toggle(); + }, + ) + ]), + onTap: () { + Navigator.of(context).pushNamed( + GymModeScreen.routeName, + arguments: _day, + ); }, - child: Container( - padding: const EdgeInsets.all(10), - decoration: BoxDecoration(color: Theme.of(context).colorScheme.inversePrimary), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - _day.description, - style: Theme.of(context).textTheme.headlineSmall, - overflow: TextOverflow.ellipsis, - ), - Text(_day.getDaysTextTranslated(Localizations.localeOf(context).languageCode)), - ], - ), - ), - IconButton( - icon: _expanded ? const Icon(Icons.unfold_less) : const Icon(Icons.unfold_more), - onPressed: () { - _toggle(); - }, - ), - ], - ), - ), ); } } diff --git a/lib/widgets/workouts/gym_mode.dart b/lib/widgets/workouts/gym_mode.dart index 81a44802d..b8241e1af 100644 --- a/lib/widgets/workouts/gym_mode.dart +++ b/lib/widgets/workouts/gym_mode.dart @@ -1131,7 +1131,7 @@ class NavigationHeader extends StatelessWidget { ), ), IconButton( - icon: const Icon(Icons.menu), + icon: const Icon(Icons.toc), onPressed: () { showDialog( context: context, diff --git a/lib/widgets/workouts/workout_plans_list.dart b/lib/widgets/workouts/workout_plans_list.dart index d2bc3d7ec..d7443bdac 100644 --- a/lib/widgets/workouts/workout_plans_list.dart +++ b/lib/widgets/workouts/workout_plans_list.dart @@ -40,81 +40,71 @@ class WorkoutPlansList extends StatelessWidget { itemCount: _workoutProvider.items.length, itemBuilder: (context, index) { final currentWorkout = _workoutProvider.items[index]; - return Dismissible( - key: Key(currentWorkout.id.toString()), - confirmDismiss: (direction) async { - // Delete workout from DB - final res = await showDialog( - context: context, - builder: (BuildContext contextDialog) { - return AlertDialog( - content: Text( - AppLocalizations.of(context).confirmDelete(currentWorkout.name), - ), - actions: [ - TextButton( - child: Text(MaterialLocalizations.of(context).cancelButtonLabel), - onPressed: () => Navigator.of(contextDialog).pop(), - ), - TextButton( - child: Text( - AppLocalizations.of(context).delete, - style: TextStyle(color: Theme.of(context).colorScheme.error), - ), - onPressed: () { - // Confirmed, delete the workout - Provider.of(context, listen: false) - .deleteWorkout(currentWorkout.id!); - // Close the popup - Navigator.of(contextDialog).pop(); - - // and inform the user - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context).successfullyDeleted, - textAlign: TextAlign.center, - ), - ), - ); - }, - ), - ], - ); - }); - return res; - }, - background: Container( - color: Theme.of(context).colorScheme.error, - alignment: Alignment.centerRight, - padding: const EdgeInsets.only(right: 20), - margin: const EdgeInsets.symmetric( - horizontal: 4, - vertical: 4, - ), - child: const Icon( - Icons.delete, - color: Colors.white, - ), - ), - direction: DismissDirection.endToStart, - child: Card( + return Card( child: ListTile( - onTap: () { - _workoutProvider.setCurrentPlan(currentWorkout.id!); + onTap: () { + _workoutProvider.setCurrentPlan(currentWorkout.id!); - Navigator.of(context) - .pushNamed(WorkoutPlanScreen.routeName, arguments: currentWorkout); - }, - title: Text(currentWorkout.name), - subtitle: Text( - DateFormat.yMd(Localizations.localeOf(context).languageCode) - .format(currentWorkout.creationDate), - ), - ), + Navigator.of(context) + .pushNamed(WorkoutPlanScreen.routeName, arguments: currentWorkout); + }, + title: Text(currentWorkout.name), + subtitle: Text( + DateFormat.yMd(Localizations.localeOf(context).languageCode) + .format(currentWorkout.creationDate), ), - ); + trailing: Row(mainAxisSize: MainAxisSize.min, children: [ + const VerticalDivider(), + IconButton( + icon: const Icon(Icons.delete), + tooltip: AppLocalizations.of(context).delete, + onPressed: () async { + // Delete workout from DB + await showDialog( + context: context, + builder: (BuildContext contextDialog) { + return AlertDialog( + content: Text( + AppLocalizations.of(context).confirmDelete(currentWorkout.name), + ), + actions: [ + TextButton( + child: + Text(MaterialLocalizations.of(context).cancelButtonLabel), + onPressed: () => Navigator.of(contextDialog).pop(), + ), + TextButton( + child: Text( + AppLocalizations.of(context).delete, + style: TextStyle(color: Theme.of(context).colorScheme.error), + ), + onPressed: () { + // Confirmed, delete the workout + Provider.of(context, listen: false) + .deleteWorkout(currentWorkout.id!); + + // Close the popup + Navigator.of(contextDialog).pop(); + + // and inform the user + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of(context).successfullyDeleted, + textAlign: TextAlign.center, + ), + ), + ); + }, + ), + ], + ); + }); + }, + ) + ]), + )); }, ), ); diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 72fa8204f..89124fad9 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -6,22 +6,50 @@ PODS: - FlutterMacOS (1.0.0) - package_info_plus (0.0.1): - FlutterMacOS + - path_provider_foundation (0.0.1): + - Flutter + - FlutterMacOS - rive_common (0.0.1): - FlutterMacOS - shared_preferences_foundation (0.0.1): - Flutter - FlutterMacOS + - sqlite3 (3.45.0): + - sqlite3/common (= 3.45.0) + - sqlite3/common (3.45.0) + - sqlite3/fts5 (3.45.0): + - sqlite3/common + - sqlite3/perf-threadsafe (3.45.0): + - sqlite3/common + - sqlite3/rtree (3.45.0): + - sqlite3/common + - sqlite3_flutter_libs (0.0.1): + - FlutterMacOS + - sqlite3 (~> 3.45.0) + - sqlite3/fts5 + - sqlite3/perf-threadsafe + - sqlite3/rtree - url_launcher_macos (0.0.1): - FlutterMacOS + - video_player_avfoundation (0.0.1): + - Flutter + - FlutterMacOS DEPENDENCIES: - file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`) - flutter_zxing (from `Flutter/ephemeral/.symlinks/plugins/flutter_zxing/macos`) - FlutterMacOS (from `Flutter/ephemeral`) - package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`) + - path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`) - rive_common (from `Flutter/ephemeral/.symlinks/plugins/rive_common/macos`) - shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`) + - sqlite3_flutter_libs (from `Flutter/ephemeral/.symlinks/plugins/sqlite3_flutter_libs/macos`) - url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`) + - video_player_avfoundation (from `Flutter/ephemeral/.symlinks/plugins/video_player_avfoundation/darwin`) + +SPEC REPOS: + trunk: + - sqlite3 EXTERNAL SOURCES: file_selector_macos: @@ -32,22 +60,32 @@ EXTERNAL SOURCES: :path: Flutter/ephemeral package_info_plus: :path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos + path_provider_foundation: + :path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin rive_common: :path: Flutter/ephemeral/.symlinks/plugins/rive_common/macos shared_preferences_foundation: :path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin + sqlite3_flutter_libs: + :path: Flutter/ephemeral/.symlinks/plugins/sqlite3_flutter_libs/macos url_launcher_macos: :path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos + video_player_avfoundation: + :path: Flutter/ephemeral/.symlinks/plugins/video_player_avfoundation/darwin SPEC CHECKSUMS: - file_selector_macos: 0f85c1108e2fd597b58246bc0b0c1cb483d7593b + file_selector_macos: 468fb6b81fac7c0e88d71317f3eec34c3b008ff9 flutter_zxing: ea030278aa2a051cd81a5b0053be9d0569d11c9a FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce - rive_common: acedcab7802c0ece4b0d838b71d7deb637e1309a - shared_preferences_foundation: 986fc17f3d3251412d18b0265f9c64113a8c2472 - url_launcher_macos: 5335912b679c073563f29d89d33d10d459f95451 + path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 + rive_common: 0f0aadf670f0c6a7872dfe3e6186f112a5319108 + shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 + sqlite3: f307b6291c4db7b5086c38d6237446b98a738581 + sqlite3_flutter_libs: 6b9913d8fbb718e5ebf23658aa6934a0fb509c0f + url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95 + video_player_avfoundation: e9e6f9cae7d7a6d9b43519b0aab382bca60fcfd1 PODFILE CHECKSUM: 0d3963a09fc94f580682bd88480486da345dc3f0 -COCOAPODS: 1.13.0 +COCOAPODS: 1.14.3 diff --git a/pubspec.lock b/pubspec.lock index fe3c4fb0f..a4158b55c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1213,10 +1213,10 @@ packages: dependency: "direct main" description: name: sqlite3_flutter_libs - sha256: "3e3583b77cf888a68eae2e49ee4f025f66b86623ef0d83c297c8d903daa14871" + sha256: "90963b515721d6a71e96f438175cf43c979493ed14822860a300b69694c74eb6" url: "https://pub.dev" source: hosted - version: "0.5.18" + version: "0.5.19+1" sqlparser: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 1ec14655c..989fa0084 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,7 +21,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # - the version number is taken from the git tag vX.Y.Z # - the build number is computed by reading the last one from the play store # and increasing by one -version: 1.6.4+39 +version: 1.7.0+40 environment: sdk: '>=3.0.0 <4.0.0' @@ -62,11 +62,12 @@ dependencies: drift: ^2.15.0 path: ^1.8.3 path_provider: ^2.1.1 - sqlite3_flutter_libs: ^0.5.18 + sqlite3_flutter_libs: ^0.5.19+1 get_it: ^7.6.4 flex_seed_scheme: ^1.4.0 flex_color_scheme: ^7.3.1 freezed_annotation: ^2.4.1 + clock: ^1.1.1 dev_dependencies: flutter_test: diff --git a/test/nutrition/nutritional_meal_form_test.dart b/test/nutrition/nutritional_meal_form_test.dart index 303e291b5..34a87b5ba 100644 --- a/test/nutrition/nutritional_meal_form_test.dart +++ b/test/nutrition/nutritional_meal_form_test.dart @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +import 'package:clock/clock.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -39,7 +40,6 @@ void main() { var plan1 = NutritionalPlan.empty(); var meal1 = Meal(); - final meal2 = Meal(); when(mockNutrition.editMeal(any)).thenAnswer((_) => Future.value(Meal())); when(mockNutrition.addMeal(any, any)).thenAnswer((_) => Future.value(Meal())); @@ -105,22 +105,40 @@ void main() { }); testWidgets('Test creating a new nutritional plan', (WidgetTester tester) async { - await tester.pumpWidget(createHomeScreen(meal2)); - await tester.pumpAndSettle(); + // DateTime.now() is difficult to mock as it pull directly from the platform + // currently being run. The clock pacakge (https://pub.dev/packages/clock) + // addresses this issue, using clock.now() allows us to set a fixed value as the + // response when using withClock. + final fixedDateTimeValue = DateTime(2020, 09, 01, 01, 01); + withClock(Clock.fixed(fixedDateTimeValue), () async { + // The time set in the meal object is what is displayed by default + // and can be matched with the find.text function. By creating the meal + // wrapped in the withClock it also shares the same now value. + final fixedTimeMeal = Meal(); - expect( - find.text(timeToString(TimeOfDay.now())!), - findsOneWidget, - reason: 'Current time is filled in', - ); + await tester.pumpWidget(createHomeScreen(fixedTimeMeal)); + await tester.pumpAndSettle(); - await tester.enterText(find.byKey(const Key('field-time')), '08:00'); - await tester.enterText(find.byKey(const Key('field-name')), 'test meal'); - await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); + expect( + clock.now(), + fixedDateTimeValue, + reason: 'Current time is set to a fixed value for testing', + ); - // Correct method was called - verifyNever(mockNutrition.editMeal(any)); - verify(mockNutrition.addMeal(any, any)); + expect( + find.text(timeToString(TimeOfDay.fromDateTime(clock.now()))!), + findsOneWidget, + reason: 'Current time is filled in', + ); + + await tester.enterText(find.byKey(const Key('field-time')), '08:00'); + await tester.enterText(find.byKey(const Key('field-name')), 'test meal'); + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); + + // Correct method was called + verifyNever(mockNutrition.editMeal(any)); + verify(mockNutrition.addMeal(any, any)); + }); // Detail page // ... diff --git a/test/nutrition/nutritional_plan_screen_test.dart b/test/nutrition/nutritional_plan_screen_test.dart index af66d0056..cea4afb8c 100644 --- a/test/nutrition/nutritional_plan_screen_test.dart +++ b/test/nutrition/nutritional_plan_screen_test.dart @@ -80,7 +80,7 @@ void main() { expect(find.text('75g Burger soup'), findsOneWidget); expect(find.text('300g Broccoli cake'), findsOneWidget); - expect(find.byType(Dismissible), findsNWidgets(2)); + expect(find.byType(Card), findsNWidgets(2)); expect(find.byType(FlNutritionalDiaryChartWidget), findsNothing); }); diff --git a/test/nutrition/nutritional_plans_screen_test.dart b/test/nutrition/nutritional_plans_screen_test.dart index b7fd34dcd..df5828334 100644 --- a/test/nutrition/nutritional_plans_screen_test.dart +++ b/test/nutrition/nutritional_plans_screen_test.dart @@ -86,14 +86,15 @@ void main() { //debugDumpApp(); expect(find.text('Nutritional plans'), findsOneWidget); - expect(find.byType(Dismissible), findsNWidgets(2)); + expect(find.byType(Card), findsNWidgets(2)); expect(find.byType(ListTile), findsNWidgets(2)); }); - testWidgets('Test deleting an item by dragging the dismissible', (WidgetTester tester) async { + testWidgets('Test deleting an item using the Delete button', (WidgetTester tester) async { await tester.pumpWidget(createHomeScreen()); - await tester.drag(find.byKey(const Key('1')), const Offset(-500.0, 0.0)); + await tester.tap(find.byIcon(Icons.delete).first); + await tester.pumpAndSettle(); // Confirmation dialog diff --git a/test/weight/weight_provider_test.dart b/test/weight/weight_provider_test.dart index 6f4dccad8..72488713d 100644 --- a/test/weight/weight_provider_test.dart +++ b/test/weight/weight_provider_test.dart @@ -31,7 +31,7 @@ import 'weight_provider_test.mocks.dart'; @GenerateMocks([WgerBaseProvider]) void main() { - var mockBaseProvider = MockWgerBaseProvider(); + late MockWgerBaseProvider mockBaseProvider; setUp(() { mockBaseProvider = MockWgerBaseProvider(); diff --git a/test/weight/weight_screen_test.dart b/test/weight/weight_screen_test.dart index 10bd75bd0..78138d3fe 100644 --- a/test/weight/weight_screen_test.dart +++ b/test/weight/weight_screen_test.dart @@ -23,32 +23,43 @@ import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:provider/provider.dart'; import 'package:wger/providers/body_weight.dart'; +import 'package:wger/providers/user.dart'; import 'package:wger/screens/form_screen.dart'; import 'package:wger/screens/weight_screen.dart'; import 'package:wger/widgets/measurements/charts.dart'; import 'package:wger/widgets/weight/forms.dart'; import '../../test_data/body_weight.dart'; +import '../../test_data/profile.dart'; import 'weight_screen_test.mocks.dart'; -@GenerateMocks([BodyWeightProvider]) +@GenerateMocks([BodyWeightProvider, UserProvider]) void main() { - var mockWeightProvider = MockBodyWeightProvider(); + late MockBodyWeightProvider mockWeightProvider; + late MockUserProvider mockUserProvider; - Widget createWeightScreen({locale = 'en'}) { + setUp(() { mockWeightProvider = MockBodyWeightProvider(); when(mockWeightProvider.items).thenReturn(getWeightEntries()); - return ChangeNotifierProvider( - create: (context) => mockWeightProvider, - child: MaterialApp( - locale: Locale(locale), - localizationsDelegates: AppLocalizations.localizationsDelegates, - supportedLocales: AppLocalizations.supportedLocales, - home: WeightScreen(), - routes: { - FormScreen.routeName: (_) => FormScreen(), - }, + mockUserProvider = MockUserProvider(); + when(mockUserProvider.profile).thenReturn(tProfile1); + }); + + Widget createWeightScreen({locale = 'en'}) { + return ChangeNotifierProvider( + create: (context) => mockUserProvider, + child: ChangeNotifierProvider( + create: (context) => mockWeightProvider, + child: MaterialApp( + locale: Locale(locale), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: WeightScreen(), + routes: { + FormScreen.routeName: (_) => FormScreen(), + }, + ), ), ); } @@ -58,17 +69,23 @@ void main() { expect(find.text('Weight'), findsOneWidget); expect(find.byType(MeasurementChartWidgetFl), findsOneWidget); - expect(find.byType(Dismissible), findsNWidgets(2)); + expect(find.byType(Card), findsNWidgets(2)); expect(find.byType(ListTile), findsNWidgets(2)); }); - testWidgets('Test deleting an item by dragging the dismissible', (WidgetTester tester) async { + testWidgets('Test deleting an item using the Delete button', (WidgetTester tester) async { + // Arrange await tester.pumpWidget(createWeightScreen()); - await tester.drag(find.byKey(const Key('1')), const Offset(-500.0, 0.0)); + // Act + expect(find.byType(ListTile), findsNWidgets(2)); + await tester.tap(find.byTooltip('Show menu').first); + await tester.pumpAndSettle(); + + // Assert + await tester.tap(find.text('Delete')); await tester.pumpAndSettle(); verify(mockWeightProvider.deleteEntry(1)).called(1); - expect(find.byType(ListTile), findsOneWidget); }); testWidgets('Test the form on the body weight screen', (WidgetTester tester) async { @@ -83,7 +100,6 @@ void main() { testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async { await tester.pumpWidget(createWeightScreen()); - // One in the entries list, one in the chart expect(find.text('1/1/2021'), findsOneWidget); expect(find.text('1/10/2021'), findsOneWidget); }); diff --git a/test/weight/weight_screen_test.mocks.dart b/test/weight/weight_screen_test.mocks.dart index 530a9aeb7..e42d7e68f 100644 --- a/test/weight/weight_screen_test.mocks.dart +++ b/test/weight/weight_screen_test.mocks.dart @@ -8,8 +8,10 @@ import 'dart:ui' as _i6; import 'package:mockito/mockito.dart' as _i1; import 'package:wger/models/body_weight/weight_entry.dart' as _i3; +import 'package:wger/models/user/profile.dart' as _i8; import 'package:wger/providers/base_provider.dart' as _i2; import 'package:wger/providers/body_weight.dart' as _i4; +import 'package:wger/providers/user.dart' as _i7; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -192,3 +194,111 @@ class MockBodyWeightProvider extends _i1.Mock implements _i4.BodyWeightProvider returnValueForMissingStub: null, ); } + +/// A class which mocks [UserProvider]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockUserProvider extends _i1.Mock implements _i7.UserProvider { + MockUserProvider() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.WgerBaseProvider get baseProvider => (super.noSuchMethod( + Invocation.getter(#baseProvider), + returnValue: _FakeWgerBaseProvider_0( + this, + Invocation.getter(#baseProvider), + ), + ) as _i2.WgerBaseProvider); + + @override + set profile(_i8.Profile? _profile) => super.noSuchMethod( + Invocation.setter( + #profile, + _profile, + ), + returnValueForMissingStub: null, + ); + + @override + bool get hasListeners => (super.noSuchMethod( + Invocation.getter(#hasListeners), + returnValue: false, + ) as bool); + + @override + void clear() => super.noSuchMethod( + Invocation.method( + #clear, + [], + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future fetchAndSetProfile() => (super.noSuchMethod( + Invocation.method( + #fetchAndSetProfile, + [], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future saveProfile() => (super.noSuchMethod( + Invocation.method( + #saveProfile, + [], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future verifyEmail() => (super.noSuchMethod( + Invocation.method( + #verifyEmail, + [], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + void addListener(_i6.VoidCallback? listener) => super.noSuchMethod( + Invocation.method( + #addListener, + [listener], + ), + returnValueForMissingStub: null, + ); + + @override + void removeListener(_i6.VoidCallback? listener) => super.noSuchMethod( + Invocation.method( + #removeListener, + [listener], + ), + returnValueForMissingStub: null, + ); + + @override + void dispose() => super.noSuchMethod( + Invocation.method( + #dispose, + [], + ), + returnValueForMissingStub: null, + ); + + @override + void notifyListeners() => super.noSuchMethod( + Invocation.method( + #notifyListeners, + [], + ), + returnValueForMissingStub: null, + ); +} diff --git a/test/workout/gym_mode_screen_test.dart b/test/workout/gym_mode_screen_test.dart index 16ad0ca10..61a5d4b66 100644 --- a/test/workout/gym_mode_screen_test.dart +++ b/test/workout/gym_mode_screen_test.dart @@ -90,7 +90,7 @@ void main() { expect(find.text('Bench press'), findsOneWidget); expect(find.text('Side raises'), findsOneWidget); expect(find.byIcon(Icons.close), findsOneWidget); - expect(find.byIcon(Icons.menu), findsOneWidget); + expect(find.byIcon(Icons.toc), findsOneWidget); expect(find.byIcon(Icons.chevron_left), findsNothing); expect(find.byIcon(Icons.chevron_right), findsOneWidget); await tester.tap(find.byIcon(Icons.chevron_right)); @@ -102,7 +102,7 @@ void main() { expect(find.text('Bench press'), findsOneWidget); expect(find.byType(ExerciseOverview), findsOneWidget); expect(find.byIcon(Icons.close), findsOneWidget); - expect(find.byIcon(Icons.menu), findsOneWidget); + expect(find.byIcon(Icons.toc), findsOneWidget); expect(find.byIcon(Icons.chevron_left), findsOneWidget); expect(find.byIcon(Icons.chevron_right), findsOneWidget); await tester.drag(find.byType(ExerciseOverview), const Offset(-500.0, 0.0)); @@ -119,7 +119,7 @@ void main() { expect(find.text('12 × 10 kg (2 RiR)'), findsOneWidget); expect(find.text('Make sure to warm up'), findsOneWidget, reason: 'Set comment'); expect(find.byIcon(Icons.close), findsOneWidget); - expect(find.byIcon(Icons.menu), findsOneWidget); + expect(find.byIcon(Icons.toc), findsOneWidget); expect(find.byIcon(Icons.chevron_left), findsOneWidget); expect(find.byIcon(Icons.chevron_right), findsOneWidget); @@ -145,7 +145,7 @@ void main() { expect(find.text('Pause'), findsOneWidget); expect(find.byType(TimerWidget), findsOneWidget); expect(find.byIcon(Icons.close), findsOneWidget); - expect(find.byIcon(Icons.menu), findsOneWidget); + expect(find.byIcon(Icons.toc), findsOneWidget); expect(find.byIcon(Icons.chevron_left), findsOneWidget); expect(find.byIcon(Icons.chevron_right), findsOneWidget); await tester.tap(find.byIcon(Icons.chevron_right)); diff --git a/test/workout/workout_plan_screen_test.dart b/test/workout/workout_plan_screen_test.dart index 5503dae04..bc06df44b 100644 --- a/test/workout/workout_plan_screen_test.dart +++ b/test/workout/workout_plan_screen_test.dart @@ -72,7 +72,7 @@ void main() { expect(find.text('3 day workout'), findsOneWidget); expect(find.text('chest, shoulders'), findsOneWidget); expect(find.text('legs'), findsOneWidget); - expect(find.byType(Dismissible), findsNWidgets(2)); + expect(find.byType(Card), findsNWidgets(2)); }); testWidgets('Tests the localization of times - EN', (WidgetTester tester) async { diff --git a/test/workout/workout_plans_screen_test.dart b/test/workout/workout_plans_screen_test.dart index dd3e880d4..621c8208f 100644 --- a/test/workout/workout_plans_screen_test.dart +++ b/test/workout/workout_plans_screen_test.dart @@ -83,14 +83,15 @@ void main() { //debugDumpApp(); expect(find.text('Workout plans'), findsOneWidget); - expect(find.byType(Dismissible), findsNWidgets(2)); + expect(find.byType(Card), findsNWidgets(2)); expect(find.byType(ListTile), findsNWidgets(2)); }); - testWidgets('Test deleting an item by dragging the dismissible', (WidgetTester tester) async { + testWidgets('Test deleting an item using the Delete button', (WidgetTester tester) async { await tester.pumpWidget(createHomeScreen()); - await tester.drag(find.byKey(const Key('1')), const Offset(-500.0, 0.0)); + await tester.tap(find.byIcon(Icons.delete).first); + await tester.pumpAndSettle(); // Confirmation dialog diff --git a/test_data/profile.dart b/test_data/profile.dart index f908c8587..f7e053f98 100644 --- a/test_data/profile.dart +++ b/test_data/profile.dart @@ -5,4 +5,5 @@ final tProfile1 = Profile( emailVerified: true, isTrustworthy: true, email: 'admin@google.com', + weightUnitStr: 'kg', );