From a589d87fad8182a0002fde014c69969ab54a3fb0 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 18 Sep 2024 15:47:58 +0300 Subject: [PATCH 1/7] dcm fix --only-rules=avoid-redundant-async --- lib/screens/measurement_categories_screen.dart | 2 +- lib/screens/measurement_entries_screen.dart | 2 +- lib/widgets/dashboard/widgets.dart | 4 ++-- test/exercises/exercise_provider_load_test.dart | 2 +- test/exercises/exercise_provider_test.dart | 2 +- test/exercises/model_exercise_test.dart | 2 +- test/measurements/measurement_provider_test.dart | 16 +++++++--------- test/other/base_provider_test.dart | 4 ++-- test/weight/weight_model_test.dart | 4 ++-- test/workout/plate_calculator_test.dart | 6 +++--- test/workout/set_model_test.dart | 2 +- test/workout/setting_model_test.dart | 10 +++++----- test/workout/workout_log_model_test.dart | 12 ++++++------ 13 files changed, 33 insertions(+), 35 deletions(-) diff --git a/lib/screens/measurement_categories_screen.dart b/lib/screens/measurement_categories_screen.dart index 6bc5e1b1..29b33d0f 100644 --- a/lib/screens/measurement_categories_screen.dart +++ b/lib/screens/measurement_categories_screen.dart @@ -34,7 +34,7 @@ class MeasurementCategoriesScreen extends StatelessWidget { appBar: AppBar(title: Text(AppLocalizations.of(context).measurements)), floatingActionButton: FloatingActionButton( child: const Icon(Icons.add, color: Colors.white), - onPressed: () async { + onPressed: () { Navigator.pushNamed( context, FormScreen.routeName, diff --git a/lib/screens/measurement_entries_screen.dart b/lib/screens/measurement_entries_screen.dart index dcbcae1a..3c8e4188 100644 --- a/lib/screens/measurement_entries_screen.dart +++ b/lib/screens/measurement_entries_screen.dart @@ -122,7 +122,7 @@ class MeasurementEntriesScreen extends StatelessWidget { ), floatingActionButton: FloatingActionButton( child: const Icon(Icons.add, color: Colors.white), - onPressed: () async { + onPressed: () { Navigator.pushNamed( context, FormScreen.routeName, diff --git a/lib/widgets/dashboard/widgets.dart b/lib/widgets/dashboard/widgets.dart index 9fc26761..d1060ec5 100644 --- a/lib/widgets/dashboard/widgets.dart +++ b/lib/widgets/dashboard/widgets.dart @@ -209,7 +209,7 @@ class _DashboardWeightWidgetState extends State { ), IconButton( icon: const Icon(Icons.add), - onPressed: () async { + onPressed: () { Navigator.pushNamed( context, FormScreen.routeName, @@ -526,7 +526,7 @@ class NothingFound extends StatelessWidget { IconButton( iconSize: 30, icon: const Icon(Icons.add_box, color: wgerPrimaryButtonColor), - onPressed: () async { + onPressed: () { Navigator.pushNamed( context, FormScreen.routeName, diff --git a/test/exercises/exercise_provider_load_test.dart b/test/exercises/exercise_provider_load_test.dart index baaef088..b12f1a59 100644 --- a/test/exercises/exercise_provider_load_test.dart +++ b/test/exercises/exercise_provider_load_test.dart @@ -41,7 +41,7 @@ void main() { await ServiceLocator().configure(); }); - setUp(() async { + setUp(() { WidgetsFlutterBinding.ensureInitialized(); driftRuntimeOptions.dontWarnAboutMultipleDatabases = true; diff --git a/test/exercises/exercise_provider_test.dart b/test/exercises/exercise_provider_test.dart index dc2aa192..0170a3fe 100644 --- a/test/exercises/exercise_provider_test.dart +++ b/test/exercises/exercise_provider_test.dart @@ -84,7 +84,7 @@ void main() { fixture('exercises/exercisebaseinfo_response.json'), ); - setUpAll(() async { + setUpAll(() { // Needs to be configured here, setUp runs on every test, setUpAll only once //await ServiceLocator().configure(); }); diff --git a/test/exercises/model_exercise_test.dart b/test/exercises/model_exercise_test.dart index 96886cb0..72e7f899 100644 --- a/test/exercises/model_exercise_test.dart +++ b/test/exercises/model_exercise_test.dart @@ -12,7 +12,7 @@ void main() { ); group('Model tests', () { - test('test getExercise', () async { + test('test getExercise', () { // arrange and act final base = getTestExercises()[1]; diff --git a/test/measurements/measurement_provider_test.dart b/test/measurements/measurement_provider_test.dart index 68157513..ea176ac8 100644 --- a/test/measurements/measurement_provider_test.dart +++ b/test/measurements/measurement_provider_test.dart @@ -240,13 +240,13 @@ void main() { test( 'should re-add the "removed" MeasurementCategory and relay the exception on WgerHttpException', - () async { + () { // arrange when(mockWgerBaseProvider.deleteRequest(any, any)).thenThrow(WgerHttpException('{}')); // act & assert - expect(() async => measurementProvider.deleteCategory(tCategoryId), - throwsA(isA())); + expect( + () => measurementProvider.deleteCategory(tCategoryId), throwsA(isA())); expect(measurementProvider.categories, tMeasurementCategories); }); }); @@ -279,9 +279,7 @@ void main() { test("should throw a NoSuchEntryException if category doesn't exist", () { // act & assert - expect( - () async => - measurementProvider.editCategory(83, tCategoryEditedName, tCategoryEditedUnit), + expect(() => measurementProvider.editCategory(83, tCategoryEditedName, tCategoryEditedUnit), throwsA(isA())); }); @@ -439,7 +437,7 @@ void main() { test("should throw a NoSuchEntryException if the category isn't found", () { // act & assert - expect(() async => measurementProvider.deleteEntry(tEntryId, 83), + expect(() => measurementProvider.deleteEntry(tEntryId, 83), throwsA(isA())); }); @@ -461,7 +459,7 @@ void main() { test( 'should re-add the "removed" MeasurementEntry and throw a WgerHttpException if the api call fails', - () async { + () { // arrange final List tMeasurementCategories = [ MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [ @@ -485,7 +483,7 @@ void main() { when(mockWgerBaseProvider.deleteRequest(any, any)).thenThrow(WgerHttpException('{}')); // act & assert - expect(() async => measurementProvider.deleteEntry(tEntryId, tCategoryId), + expect(() => measurementProvider.deleteEntry(tEntryId, tCategoryId), throwsA(isA())); expect(measurementProvider.categories, tMeasurementCategories); }); diff --git a/test/other/base_provider_test.dart b/test/other/base_provider_test.dart index e416e1b8..3f3376d2 100644 --- a/test/other/base_provider_test.dart +++ b/test/other/base_provider_test.dart @@ -30,7 +30,7 @@ import 'base_provider_test.mocks.dart'; @GenerateMocks([http.Client]) void main() { group('test base provider', () { - test('Test the makeUrl helper', () async { + test('Test the makeUrl helper', () { final WgerBaseProvider provider = WgerBaseProvider(testAuthProvider); expect( @@ -63,7 +63,7 @@ void main() { ); }); - test('Test the makeUrl helper with sub url', () async { + test('Test the makeUrl helper with sub url', () { // Trailing slash is removed when saving the server URL testAuthProvider.serverUrl = 'https://example.com/wger-url'; final WgerBaseProvider provider = WgerBaseProvider(testAuthProvider); diff --git a/test/weight/weight_model_test.dart b/test/weight/weight_model_test.dart index f903f370..0866d83e 100644 --- a/test/weight/weight_model_test.dart +++ b/test/weight/weight_model_test.dart @@ -21,7 +21,7 @@ import 'package:wger/models/body_weight/weight_entry.dart'; void main() { group('fetchPost', () { - test('Test that the weight entries are correctly converted to json', () async { + test('Test that the weight entries are correctly converted to json', () { WeightEntry weightEntry = WeightEntry(id: 1, weight: 80, date: DateTime(2020, 12, 31)); expect(weightEntry.toJson(), {'id': 1, 'weight': '80', 'date': '2020-12-31'}); @@ -29,7 +29,7 @@ void main() { expect(weightEntry.toJson(), {'id': 2, 'weight': '70.2', 'date': '2020-12-01'}); }); - test('Test that the weight entries are correctly converted from json', () async { + test('Test that the weight entries are correctly converted from json', () { final WeightEntry weightEntryObj = WeightEntry(id: 1, weight: 80, date: DateTime(2020, 12, 31)); final WeightEntry weightEntry = WeightEntry.fromJson({ diff --git a/test/workout/plate_calculator_test.dart b/test/workout/plate_calculator_test.dart index e1150406..60a1b017 100644 --- a/test/workout/plate_calculator_test.dart +++ b/test/workout/plate_calculator_test.dart @@ -22,7 +22,7 @@ import 'package:wger/helpers/gym_mode.dart'; void main() { group('Test the plate calculator', () { - test('Regular weights', () async { + test('Regular weights', () { expect(plateCalculator(40, BAR_WEIGHT, AVAILABLE_PLATES), [10]); expect(plateCalculator(100, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 10]); expect(plateCalculator(102.5, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 10, 1.25]); @@ -31,7 +31,7 @@ void main() { expect(plateCalculator(85, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 2.5]); }); - test('Exceptions', () async { + test('Exceptions', () { expect( plateCalculator(10, BAR_WEIGHT, AVAILABLE_PLATES), [], @@ -47,7 +47,7 @@ void main() { }); group('Test the plate calculator group', () { - test('Test groups', () async { + test('Test groups', () { expect(groupPlates([15, 15, 15, 10, 10, 5]), {15: 3, 10: 2, 5: 1}); expect(groupPlates([15, 10, 5, 1.25]), {15: 1, 10: 1, 5: 1, 1.25: 1}); expect(groupPlates([10, 10, 10, 10, 10, 10, 10]), {10: 7}); diff --git a/test/workout/set_model_test.dart b/test/workout/set_model_test.dart index dfd4b0e8..b055d149 100644 --- a/test/workout/set_model_test.dart +++ b/test/workout/set_model_test.dart @@ -22,7 +22,7 @@ import '../../test_data/workouts.dart'; void main() { group('Test the getSmartTextRepr method for a set', () { - test('Repetitions and weigh units', () async { + test('Repetitions and weigh units', () { final workout = getWorkout(); final set = workout.days.first.sets.first; final exercise1 = set.exerciseBasesObj[0]; diff --git a/test/workout/setting_model_test.dart b/test/workout/setting_model_test.dart index 53d2381c..bec0a052 100644 --- a/test/workout/setting_model_test.dart +++ b/test/workout/setting_model_test.dart @@ -23,7 +23,7 @@ import 'package:wger/models/workouts/weight_unit.dart'; void main() { group('Test the singleSettingRepText method', () { - test('Default rep and weight units, no RiR', () async { + test('Default rep and weight units, no RiR', () { const repUnit = RepetitionUnit(id: 1, name: 'mol'); const weightUnit = WeightUnit(id: 1, name: 'mg'); @@ -36,7 +36,7 @@ void main() { expect(setting.singleSettingRepText, '2 × 30 mg'); }); - test('Default rep and weight units', () async { + test('Default rep and weight units', () { const repUnit = RepetitionUnit(id: 1, name: 'mol'); const weightUnit = WeightUnit(id: 1, name: 'mg'); @@ -49,7 +49,7 @@ void main() { expect(setting.singleSettingRepText, '2 × 30 mg \n (1.5 RiR)'); }); - test('No weight, default rep and weight units', () async { + test('No weight, default rep and weight units', () { const repUnit = RepetitionUnit(id: 1, name: 'mol'); const weightUnit = WeightUnit(id: 1, name: 'mg'); @@ -62,7 +62,7 @@ void main() { expect(setting.singleSettingRepText, '2 mol \n (1.5 RiR)'); }); - test('Custom rep and weight units, no RiR', () async { + test('Custom rep and weight units, no RiR', () { const repUnit = RepetitionUnit(id: 2, name: 'mol'); const weightUnit = WeightUnit(id: 2, name: 'mg'); @@ -75,7 +75,7 @@ void main() { expect(setting.singleSettingRepText, '2 mol × 30 mg'); }); - test('Custom rep and weight units, RiR', () async { + test('Custom rep and weight units, RiR', () { const repUnit = RepetitionUnit(id: 2, name: 'mol'); const weightUnit = WeightUnit(id: 2, name: 'mg'); diff --git a/test/workout/workout_log_model_test.dart b/test/workout/workout_log_model_test.dart index f7f381d9..a53e7ae3 100644 --- a/test/workout/workout_log_model_test.dart +++ b/test/workout/workout_log_model_test.dart @@ -49,31 +49,31 @@ void main() { ); }); - test('Test equal values (besides Id, workoutPlan and date)', () async { + test('Test equal values (besides Id, workoutPlan and date)', () { expect(log1, log2); }); - test('Test different rir values', () async { + test('Test different rir values', () { log1.rir = null; expect(log1, isNot(log2)); }); - test('Test different weight values', () async { + test('Test different weight values', () { log1.weight = 100; expect(log1, isNot(log2)); }); - test('Test different weight units', () async { + test('Test different weight units', () { log1.weightUnitId = 2; expect(log1, isNot(log2)); }); - test('Test different reps', () async { + test('Test different reps', () { log1.reps = 99; expect(log1, isNot(log2)); }); - test('Test different rep units', () async { + test('Test different rep units', () { log1.repetitionUnitId = 44; expect(log1, isNot(log2)); }); From 66ced6ccc434042cfc294554adc27d524269056c Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 18 Sep 2024 15:55:06 +0300 Subject: [PATCH 2/7] dcm fix --only-rules=prefer-trailing-comma lib test test_data integration_test --- integration_test/1_dashboard.dart | 6 +- integration_test/6_weight.dart | 4 +- integration_test/make_screenshots_test.dart | 2 +- test/core/settings_test.dart | 9 +- .../exercise_provider_load_test.dart | 2 +- test/exercises/model_exercise_test.dart | 2 +- test/gallery/gallery_provider_test.dart | 37 +-- .../measurement_category_test.dart | 4 +- test/measurements/measurement_entry_test.dart | 7 +- .../measurement_provider_test.dart | 240 ++++++++++-------- .../nutritional_meal_item_form_test.dart | 61 +++-- .../nutritional_plan_model_test.dart | 105 ++++---- test/weight/weight_provider_test.dart | 5 +- test/workout/workout_form_test.dart | 6 +- test/workout/workout_provider_test.dart | 4 +- test/workout/workout_set_form_test.dart | 21 +- test_data/gallery.dart | 2 +- test_data/screenshots_exercises.dart | 4 +- 18 files changed, 284 insertions(+), 237 deletions(-) diff --git a/integration_test/1_dashboard.dart b/integration_test/1_dashboard.dart index b59a7be6..4550fea7 100644 --- a/integration_test/1_dashboard.dart +++ b/integration_test/1_dashboard.dart @@ -34,9 +34,9 @@ Widget createDashboardScreen({locale = 'en'}) { 'date': '2022-12-01', 'impression': '3', 'time_start': '17:00', - 'time_end': '19:00' - } - ] + 'time_end': '19:00', + }, + ], }; when(mockWorkoutProvider.fetchSessionData()).thenAnswer((a) => Future.value(logs)); diff --git a/integration_test/6_weight.dart b/integration_test/6_weight.dart index 6da0995d..57f46609 100644 --- a/integration_test/6_weight.dart +++ b/integration_test/6_weight.dart @@ -36,9 +36,7 @@ Widget createWeightScreen({locale = 'en'}) { supportedLocales: AppLocalizations.supportedLocales, theme: wgerLightTheme, home: const WeightScreen(), - routes: { - FormScreen.routeName: (ctx) => const FormScreen(), - }, + routes: {FormScreen.routeName: (ctx) => const FormScreen()}, ), ); } diff --git a/integration_test/make_screenshots_test.dart b/integration_test/make_screenshots_test.dart index c197d769..78ce1222 100644 --- a/integration_test/make_screenshots_test.dart +++ b/integration_test/make_screenshots_test.dart @@ -57,7 +57,7 @@ const languages = [ 'ru-RU', 'tr-TR', 'uk', - 'zh-CN' + 'zh-CN', ]; void main() { diff --git a/test/core/settings_test.dart b/test/core/settings_test.dart index 213fae58..1b2fa453 100644 --- a/test/core/settings_test.dart +++ b/test/core/settings_test.dart @@ -35,10 +35,11 @@ void main() { return ChangeNotifierProvider( create: (context) => mockExerciseProvider, child: MaterialApp( - locale: Locale(locale), - localizationsDelegates: AppLocalizations.localizationsDelegates, - supportedLocales: AppLocalizations.supportedLocales, - home: const SettingsPage()), + locale: Locale(locale), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: const SettingsPage(), + ), ); } diff --git a/test/exercises/exercise_provider_load_test.dart b/test/exercises/exercise_provider_load_test.dart index b12f1a59..bc809b5c 100644 --- a/test/exercises/exercise_provider_load_test.dart +++ b/test/exercises/exercise_provider_load_test.dart @@ -114,7 +114,7 @@ void main() { '1f5d2b2f-d4ea-4eeb-9377-56176465e08d', 'ab645585-26ef-4992-a9ec-15425687ece9', 'd8aa5990-bb47-4111-9823-e2fbd98fe07f', - '49a159e1-1e00-409a-81c9-b4d4489fbd67' + '49a159e1-1e00-409a-81c9-b4d4489fbd67', ]); expect(exercise.videos.map((v) => v.uuid), ['63e996e9-a772-4ca5-9d09-8b4be03f6be4']); diff --git a/test/exercises/model_exercise_test.dart b/test/exercises/model_exercise_test.dart index 72e7f899..2d817ba0 100644 --- a/test/exercises/model_exercise_test.dart +++ b/test/exercises/model_exercise_test.dart @@ -57,7 +57,7 @@ void main() { '1f5d2b2f-d4ea-4eeb-9377-56176465e08d', 'ab645585-26ef-4992-a9ec-15425687ece9', 'd8aa5990-bb47-4111-9823-e2fbd98fe07f', - '49a159e1-1e00-409a-81c9-b4d4489fbd67' + '49a159e1-1e00-409a-81c9-b4d4489fbd67', ]); expect(exercise.videos.map((v) => v.uuid), ['63e996e9-a772-4ca5-9d09-8b4be03f6be4']); diff --git a/test/gallery/gallery_provider_test.dart b/test/gallery/gallery_provider_test.dart index a7b20a80..b0e067b6 100644 --- a/test/gallery/gallery_provider_test.dart +++ b/test/gallery/gallery_provider_test.dart @@ -34,13 +34,14 @@ void main() { Uri.https('localhost', 'api/v2/gallery/'), headers: anyNamed('headers'), )).thenAnswer((_) async => http.Response( - '{"count":1,"next":null,"previous":null,"results":[' - '{"id":58,' - '"date":"2022-01-09",' - '"image":"https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg",' - '"description":"eggsaddjujuit\'ddayhadIforcanview",' - '"height":1280,"width":960}]}', - 200)); + '{"count":1,"next":null,"previous":null,"results":[' + '{"id":58,' + '"date":"2022-01-09",' + '"image":"https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg",' + '"description":"eggsaddjujuit\'ddayhadIforcanview",' + '"height":1280,"width":960}]}', + 200, + )); final galleryProvider = GalleryProvider(testAuthProvider, [], client); @@ -57,20 +58,22 @@ void main() { Uri.https('localhost', 'api/v2/gallery/58/'), headers: anyNamed('headers'), )).thenAnswer((_) async => http.Response( - '{"id":58,' - '"date":"2022-01-09",' - '"image":"https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg",' - '"description":"eggsaddjujuit\'ddayhadIforcanview",' - '"height":1280,"width":960}', - 200)); + '{"id":58,' + '"date":"2022-01-09",' + '"image":"https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg",' + '"description":"eggsaddjujuit\'ddayhadIforcanview",' + '"height":1280,"width":960}', + 200, + )); final galleryProvider = GalleryProvider(testAuthProvider, [], client); final image = gallery.Image( - id: 58, - date: DateTime(2022, 01, 09), - url: 'https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg', - description: "eggsaddjujuit'ddayhadIforcanview"); + id: 58, + date: DateTime(2022, 01, 09), + url: 'https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg', + description: "eggsaddjujuit'ddayhadIforcanview", + ); galleryProvider.images.add(image); diff --git a/test/measurements/measurement_category_test.dart b/test/measurements/measurement_category_test.dart index 0f66a73e..21009d0e 100644 --- a/test/measurements/measurement_category_test.dart +++ b/test/measurements/measurement_category_test.dart @@ -11,7 +11,7 @@ void main() { date: DateTime(2021, 7, 22), value: 83, notes: 'notes', - ) + ), ]; final MeasurementEntry tMeasurementEntry = MeasurementEntry( @@ -35,7 +35,7 @@ void main() { 'category': 123, 'date': '2021-07-22', 'value': 83, - 'notes': 'notes' + 'notes': 'notes', }; final Map tMeasurementCategoryMap = { diff --git a/test/measurements/measurement_entry_test.dart b/test/measurements/measurement_entry_test.dart index 8c535b06..7e972fe0 100644 --- a/test/measurements/measurement_entry_test.dart +++ b/test/measurements/measurement_entry_test.dart @@ -47,7 +47,12 @@ void main() { // act final result = tMeasurementEntry.copyWith( - id: 83, category: 17, date: DateTime(1960), value: 93, notes: 'Interesting'); + id: 83, + category: 17, + date: DateTime(1960), + value: 93, + notes: 'Interesting', + ); // assert expect(result, tMeasurementEntryCopied); diff --git a/test/measurements/measurement_provider_test.dart b/test/measurements/measurement_provider_test.dart index ea176ac8..90f60bc1 100644 --- a/test/measurements/measurement_provider_test.dart +++ b/test/measurements/measurement_provider_test.dart @@ -38,7 +38,7 @@ void main() { MeasurementCategory(id: 1, name: 'Strength', unit: 'kN'); final List tMeasurementCategories = [ const MeasurementCategory(id: 1, name: 'Strength', unit: 'kN'), - const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm') + const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'), ]; final Map tMeasurementCategoriesMap = jsonDecode(fixture('measurement/measurement_categories.json')); @@ -158,9 +158,9 @@ void main() { date: DateTime(2021, 7, 10), value: 15.00, notes: '', - ) + ), ]), - const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm') + const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'), ]; // act @@ -197,17 +197,18 @@ void main() { }); test( - 'should add the result from the post call to the categories List and sort the list by alphabetical order', - () async { - // arrange - await measurementProvider.fetchAndSetCategories(); + 'should add the result from the post call to the categories List and sort the list by alphabetical order', + () async { + // arrange + await measurementProvider.fetchAndSetCategories(); - // act - await measurementProvider.addCategory(tMeasurementCategoryWithoutId); + // act + await measurementProvider.addCategory(tMeasurementCategoryWithoutId); - // assert - expect(measurementProvider.categories, tMeasurementCategoriesAdded); - }); + // assert + expect(measurementProvider.categories, tMeasurementCategoriesAdded); + }, + ); }); group('deleteCategory()', () { @@ -215,23 +216,24 @@ void main() { await measurementProvider.fetchAndSetCategories(); }); test( - 'should remove a MeasurementCategory from the categories list for an id and call the api to remove the MeasurementCategory', - () async { - // arrange - when(mockWgerBaseProvider.deleteRequest(any, any)) - .thenAnswer((realInvocation) => Future.value(Response('', 200))); + 'should remove a MeasurementCategory from the categories list for an id and call the api to remove the MeasurementCategory', + () async { + // arrange + when(mockWgerBaseProvider.deleteRequest(any, any)) + .thenAnswer((realInvocation) => Future.value(Response('', 200))); - final List tMeasurementCategoriesOneDeleted = [ - const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm') - ]; + final List tMeasurementCategoriesOneDeleted = [ + const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'), + ]; - // act - await measurementProvider.deleteCategory(tCategoryId); + // act + await measurementProvider.deleteCategory(tCategoryId); - // assert - verify(mockWgerBaseProvider.deleteRequest('measurement-category', tCategoryId)); - expect(measurementProvider.categories, tMeasurementCategoriesOneDeleted); - }); + // assert + verify(mockWgerBaseProvider.deleteRequest('measurement-category', tCategoryId)); + expect(measurementProvider.categories, tMeasurementCategoriesOneDeleted); + }, + ); test('should throw a NoSuchEntryException if no category is found', () { // act & assert @@ -239,16 +241,19 @@ void main() { }); test( - 'should re-add the "removed" MeasurementCategory and relay the exception on WgerHttpException', - () { - // arrange - when(mockWgerBaseProvider.deleteRequest(any, any)).thenThrow(WgerHttpException('{}')); + 'should re-add the "removed" MeasurementCategory and relay the exception on WgerHttpException', + () { + // arrange + when(mockWgerBaseProvider.deleteRequest(any, any)).thenThrow(WgerHttpException('{}')); - // act & assert - expect( - () => measurementProvider.deleteCategory(tCategoryId), throwsA(isA())); - expect(measurementProvider.categories, tMeasurementCategories); - }); + // act & assert + expect( + () => measurementProvider.deleteCategory(tCategoryId), + throwsA(isA()), + ); + expect(measurementProvider.categories, tMeasurementCategories); + }, + ); }); group('editCategory()', () { @@ -279,8 +284,10 @@ void main() { test("should throw a NoSuchEntryException if category doesn't exist", () { // act & assert - expect(() => measurementProvider.editCategory(83, tCategoryEditedName, tCategoryEditedUnit), - throwsA(isA())); + expect( + () => measurementProvider.editCategory(83, tCategoryEditedName, tCategoryEditedUnit), + throwsA(isA()), + ); }); test('should call api to patch the category', () async { @@ -297,9 +304,13 @@ void main() { // act & assert expect( - () => measurementProvider.editCategory( - tCategoryId, tCategoryEditedName, tCategoryEditedUnit), - throwsA(isA())); + () => measurementProvider.editCategory( + tCategoryId, + tCategoryEditedName, + tCategoryEditedUnit, + ), + throwsA(isA()), + ); expect(measurementProvider.categories, tMeasurementCategories); }); }); @@ -337,9 +348,9 @@ void main() { value: 15.00, notes: '', ), - tMeasurementEntry + tMeasurementEntry, ]), - const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm') + const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'), ]; setUp(() async { @@ -372,17 +383,18 @@ void main() { }); test( - "should add MeasurementEntry to its MeasurementCategory in the categories List and sort the category's list by date", - () async { - // arrange - await measurementProvider.fetchAndSetCategoryEntries(tCategoryId); + "should add MeasurementEntry to its MeasurementCategory in the categories List and sort the category's list by date", + () async { + // arrange + await measurementProvider.fetchAndSetCategoryEntries(tCategoryId); - // act - await measurementProvider.addEntry(tMeasurementEntryWithoutId); + // act + await measurementProvider.addEntry(tMeasurementEntryWithoutId); - // assert - expect(measurementProvider.categories, tMeasurementCategories); - }); + // assert + expect(measurementProvider.categories, tMeasurementCategories); + }, + ); test('should throw a NoSuchEntryException if no category is found', () { // arrange @@ -399,8 +411,10 @@ void main() { .thenAnswer((realInvocation) => Future.value(measurementEntryMapWrongCategory)); // act & assert - expect(() => measurementProvider.addEntry(tMeasurementEntryWrongCategory), - throwsA(isA())); + expect( + () => measurementProvider.addEntry(tMeasurementEntryWrongCategory), + throwsA(isA()), + ); }); }); @@ -416,7 +430,7 @@ void main() { notes: 'Some important notes', ), ]), - const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm') + const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'), ]; setUp(() async { @@ -437,17 +451,22 @@ void main() { test("should throw a NoSuchEntryException if the category isn't found", () { // act & assert - expect(() => measurementProvider.deleteEntry(tEntryId, 83), - throwsA(isA())); + expect( + () => measurementProvider.deleteEntry(tEntryId, 83), + throwsA(isA()), + ); }); test( - "should throw a NoSuchEntryException if the entry in the categories entries List isn't found", - () { - // act & assert - expect(() => measurementProvider.deleteEntry(83, tCategoryId), - throwsA(isA())); - }); + "should throw a NoSuchEntryException if the entry in the categories entries List isn't found", + () { + // act & assert + expect( + () => measurementProvider.deleteEntry(83, tCategoryId), + throwsA(isA()), + ); + }, + ); test('should call the api to remove the MeasurementEntry', () async { // act @@ -458,35 +477,38 @@ void main() { }); test( - 'should re-add the "removed" MeasurementEntry and throw a WgerHttpException if the api call fails', - () { - // arrange - final List tMeasurementCategories = [ - MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [ - MeasurementEntry( - id: 1, - category: 1, - date: DateTime(2021, 7, 21), - value: 10, - notes: 'Some important notes', - ), - MeasurementEntry( - id: 2, - category: 1, - date: DateTime(2021, 7, 10), - value: 15.00, - notes: '', - ), - ]), - const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm') - ]; - when(mockWgerBaseProvider.deleteRequest(any, any)).thenThrow(WgerHttpException('{}')); + 'should re-add the "removed" MeasurementEntry and throw a WgerHttpException if the api call fails', + () { + // arrange + final List tMeasurementCategories = [ + MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [ + MeasurementEntry( + id: 1, + category: 1, + date: DateTime(2021, 7, 21), + value: 10, + notes: 'Some important notes', + ), + MeasurementEntry( + id: 2, + category: 1, + date: DateTime(2021, 7, 10), + value: 15.00, + notes: '', + ), + ]), + const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'), + ]; + when(mockWgerBaseProvider.deleteRequest(any, any)).thenThrow(WgerHttpException('{}')); - // act & assert - expect(() => measurementProvider.deleteEntry(tEntryId, tCategoryId), - throwsA(isA())); - expect(measurementProvider.categories, tMeasurementCategories); - }); + // act & assert + expect( + () => measurementProvider.deleteEntry(tEntryId, tCategoryId), + throwsA(isA()), + ); + expect(measurementProvider.categories, tMeasurementCategories); + }, + ); }); group('editEntry()', () { @@ -525,9 +547,9 @@ void main() { date: DateTime(2021, 7, 10), value: 15.00, notes: '', - ) + ), ]), - const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm') + const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'), ]; // act @@ -546,27 +568,29 @@ void main() { test("should throw a NoSuchEntryException if category doesn't exist", () { // act & assert expect( - () => measurementProvider.editEntry( - tEntryId, - 83, - tEntryEditedValue, - tEntryEditedNote, - tEntryEditedDate, - ), - throwsA(isA())); + () => measurementProvider.editEntry( + tEntryId, + 83, + tEntryEditedValue, + tEntryEditedNote, + tEntryEditedDate, + ), + throwsA(isA()), + ); }); test("should throw a NoSuchEntryException if entry doesn't exist", () { // act & assert expect( - () => measurementProvider.editEntry( - 83, - tCategoryId, - tEntryEditedValue, - tEntryEditedNote, - tEntryEditedDate, - ), - throwsA(isA())); + () => measurementProvider.editEntry( + 83, + tCategoryId, + tEntryEditedValue, + tEntryEditedNote, + tEntryEditedDate, + ), + throwsA(isA()), + ); }); test('should call api to patch the entry', () async { diff --git a/test/nutrition/nutritional_meal_item_form_test.dart b/test/nutrition/nutritional_meal_item_form_test.dart index ba5de3f0..fddca2b3 100644 --- a/test/nutrition/nutritional_meal_item_form_test.dart +++ b/test/nutrition/nutritional_meal_item_form_test.dart @@ -81,12 +81,15 @@ void main() { when(mockNutrition.searchIngredientWithCode('123')).thenAnswer((_) => Future.value(ingredient)); when(mockNutrition.searchIngredientWithCode('')).thenAnswer((_) => Future.value(null)); when(mockNutrition.searchIngredientWithCode('222')).thenAnswer((_) => Future.value(null)); - when(mockNutrition.searchIngredient(any, - languageCode: anyNamed('languageCode'), searchEnglish: anyNamed('searchEnglish'))) - .thenAnswer( + when(mockNutrition.searchIngredient( + any, + languageCode: anyNamed('languageCode'), + searchEnglish: anyNamed('searchEnglish'), + )).thenAnswer( (_) => Future.value( - IngredientApiSearch.fromJson(json.decode(fixture('nutrition/ingredient_suggestions'))) - .suggestions), + IngredientApiSearch.fromJson(json.decode(fixture('nutrition/ingredient_suggestions'))) + .suggestions, + ), ); when(mockNutrition.addMealItem(any, meal1)).thenAnswer((_) => Future.value(mealItem)); @@ -280,7 +283,7 @@ void main() { expect(find.text('Please enter a valid number'), findsOneWidget); }); -//TODO: isn't this test just a duplicate of the above one? can be removed? + //TODO: isn't this test just a duplicate of the above one? can be removed? testWidgets('save ingredient with incorrect weight input type', (WidgetTester tester) async { await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); @@ -298,38 +301,40 @@ void main() { expect(find.text('Please enter a valid number'), findsOneWidget); }); - testWidgets('save complete ingredient with correct weight input type', - (WidgetTester tester) async { - await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + testWidgets( + 'save complete ingredient with correct weight input type', + (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); - final IngredientFormState formState = tester.state(find.byType(IngredientForm)); + final IngredientFormState formState = tester.state(find.byType(IngredientForm)); - await tester.tap(find.byKey(const Key('scan-button'))); - await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('scan-button'))); + await tester.pumpAndSettle(); - expect(find.byKey(const Key('ingredient-scan-result-dialog')), findsOneWidget); + expect(find.byKey(const Key('ingredient-scan-result-dialog')), findsOneWidget); - await tester.tap(find.byKey(const Key('ingredient-scan-result-dialog-confirm-button'))); - await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('ingredient-scan-result-dialog-confirm-button'))); + await tester.pumpAndSettle(); - expect(formState.ingredientIdController.text, '1'); + expect(formState.ingredientIdController.text, '1'); - await tester.enterText(find.byKey(const Key('field-weight')), '2'); + await tester.enterText(find.byKey(const Key('field-weight')), '2'); - // once ID and weight are set, it'll fetchIngredient and show macros preview and ingredient image - when(mockNutrition.fetchIngredient(1)).thenAnswer((_) => Future.value( - Ingredient.fromJson(jsonDecode(fixture('nutrition/ingredientinfo_59887.json'))), - )); - await mockNetworkImagesFor(() => tester.pumpAndSettle()); + // once ID and weight are set, it'll fetchIngredient and show macros preview and ingredient image + when(mockNutrition.fetchIngredient(1)).thenAnswer((_) => Future.value( + Ingredient.fromJson(jsonDecode(fixture('nutrition/ingredientinfo_59887.json'))), + )); + await mockNetworkImagesFor(() => tester.pumpAndSettle()); - expect(find.byKey(const Key('ingredient-scan-result-dialog')), findsNothing); + expect(find.byKey(const Key('ingredient-scan-result-dialog')), findsNothing); - await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); - await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); + await tester.pumpAndSettle(); - expect(formState.mealItem.amount, 2); + expect(formState.mealItem.amount, 2); - verify(mockNutrition.addMealItem(any, meal1)); - }); + verify(mockNutrition.addMealItem(any, meal1)); + }, + ); }); } diff --git a/test/nutrition/nutritional_plan_model_test.dart b/test/nutrition/nutritional_plan_model_test.dart index a48fa468..ac35a162 100644 --- a/test/nutrition/nutritional_plan_model_test.dart +++ b/test/nutrition/nutritional_plan_model_test.dart @@ -33,65 +33,70 @@ void main() { group('model tests', () { test('Test NutritionalPlan.nutritionalGoals based on meals', () { expect( - plan.nutritionalGoals, - NutritionalGoals( - energy: 4118.75, - protein: 32.75, - carbohydrates: 347.5, - carbohydratesSugar: 9.5, - fat: 59.0, - fatSaturated: 37.75, - fiber: 52.5, - sodium: 30.5)); + plan.nutritionalGoals, + NutritionalGoals( + energy: 4118.75, + protein: 32.75, + carbohydrates: 347.5, + carbohydratesSugar: 9.5, + fat: 59.0, + fatSaturated: 37.75, + fiber: 52.5, + sodium: 30.5, + ), + ); }); test('Test NutritionalPlan.nutritionalValues based on 3 macros and energy', () { expect( - NutritionalPlan( - description: '3 macros and energy defined', - creationDate: DateTime(2024, 5, 4), - goalProtein: 150, - goalCarbohydrates: 100, - goalFat: 100, - goalEnergy: 1500, - ).nutritionalGoals, - NutritionalGoals( - energy: 1500, - protein: 150, - carbohydrates: 100, - fat: 100, - )); + NutritionalPlan( + description: '3 macros and energy defined', + creationDate: DateTime(2024, 5, 4), + goalProtein: 150, + goalCarbohydrates: 100, + goalFat: 100, + goalEnergy: 1500, + ).nutritionalGoals, + NutritionalGoals( + energy: 1500, + protein: 150, + carbohydrates: 100, + fat: 100, + ), + ); }); test('Test NutritionalPlan.nutritionalValues based on 2 macros and energy', () { expect( - NutritionalPlan( - description: '2 macros and energy defined', - creationDate: DateTime(2024, 5, 4), - goalProtein: 100, - goalCarbohydrates: 100, - goalEnergy: 1700, - ).nutritionalGoals, - NutritionalGoals( - energy: 1700, - protein: 100, - carbohydrates: 100, - fat: 100, // inferred - )); + NutritionalPlan( + description: '2 macros and energy defined', + creationDate: DateTime(2024, 5, 4), + goalProtein: 100, + goalCarbohydrates: 100, + goalEnergy: 1700, + ).nutritionalGoals, + NutritionalGoals( + energy: 1700, + protein: 100, + carbohydrates: 100, + fat: 100, // inferred + ), + ); }); test('Test NutritionalPlan.nutritionalValues based on 3 macros only', () { expect( - NutritionalPlan( - description: '3 macros defined', - creationDate: DateTime(2024, 5, 4), - goalProtein: 100, - goalCarbohydrates: 100, - goalFat: 10, - ).nutritionalGoals, - NutritionalGoals( - energy: 890, // inferred - protein: 100, - carbohydrates: 100, - fat: 10, - )); + NutritionalPlan( + description: '3 macros defined', + creationDate: DateTime(2024, 5, 4), + goalProtein: 100, + goalCarbohydrates: 100, + goalFat: 10, + ).nutritionalGoals, + NutritionalGoals( + energy: 890, // inferred + protein: 100, + carbohydrates: 100, + fat: 10, + ), + ); }); test('Test the nutritionalValues method for meals', () { diff --git a/test/weight/weight_provider_test.dart b/test/weight/weight_provider_test.dart index 72488713..08ce8c66 100644 --- a/test/weight/weight_provider_test.dart +++ b/test/weight/weight_provider_test.dart @@ -93,14 +93,15 @@ void main() { ); when(mockBaseProvider.makeUrl(any, query: anyNamed('query'))).thenReturn(uri); when(mockBaseProvider.deleteRequest('weightentry', 4)).thenAnswer( - (_) => Future.value(Response("{'id': 4, 'date': '2021-01-01', 'weight': '80'}", 204))); + (_) => Future.value(Response("{'id': 4, 'date': '2021-01-01', 'weight': '80'}", 204)), + ); // DELETE the data from the server final BodyWeightProvider provider = BodyWeightProvider(mockBaseProvider); provider.items = [ WeightEntry(id: 4, weight: 80, date: DateTime(2021, 1, 1)), WeightEntry(id: 2, weight: 100, date: DateTime(2021, 2, 2)), - WeightEntry(id: 5, weight: 60, date: DateTime(2021, 2, 2)) + WeightEntry(id: 5, weight: 60, date: DateTime(2021, 2, 2)), ]; await provider.deleteEntry(4); diff --git a/test/workout/workout_form_test.dart b/test/workout/workout_form_test.dart index 75af21b4..a3ddd7f4 100644 --- a/test/workout/workout_form_test.dart +++ b/test/workout/workout_form_test.dart @@ -133,7 +133,11 @@ void main() { testWidgets('Test creating a new workout - name and description', (WidgetTester tester) async { final editWorkout = WorkoutPlan( - id: 2, creationDate: newPlan.creationDate, name: 'My workout', description: 'Get yuuuge'); + id: 2, + creationDate: newPlan.creationDate, + name: 'My workout', + description: 'Get yuuuge', + ); when(mockWorkoutPlans.addWorkout(any)).thenAnswer((_) => Future.value(editWorkout)); await tester.pumpWidget(createHomeScreen(newPlan)); diff --git a/test/workout/workout_provider_test.dart b/test/workout/workout_provider_test.dart index f49ee03a..1bcb7d4f 100644 --- a/test/workout/workout_provider_test.dart +++ b/test/workout/workout_provider_test.dart @@ -58,7 +58,7 @@ void main() { 'id': 325397, 'name': 'Test workout', 'creation_date': '2022-10-10', - 'description': 'Test workout abcd' + 'description': 'Test workout abcd', }), ); @@ -85,7 +85,7 @@ void main() { 'id': 325397, 'name': 'Test workout', 'creation_date': '2022-10-10', - 'description': 'Test workout abcd' + 'description': 'Test workout abcd', }), ); when(mockBaseProvider.deleteRequest('workout', 325397)).thenAnswer( diff --git a/test/workout/workout_set_form_test.dart b/test/workout/workout_set_form_test.dart index 3d298007..50479298 100644 --- a/test/workout/workout_set_form_test.dart +++ b/test/workout/workout_set_form_test.dart @@ -57,16 +57,17 @@ void main() { [workoutPlan], ), child: ChangeNotifierProvider( - create: (context) => mockExerciseProvider, - child: MaterialApp( - locale: Locale(locale), - localizationsDelegates: AppLocalizations.localizationsDelegates, - supportedLocales: AppLocalizations.supportedLocales, - navigatorKey: GlobalKey(), - home: Scaffold( - body: SetFormWidget(day), - ), - )), + create: (context) => mockExerciseProvider, + child: MaterialApp( + locale: Locale(locale), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + navigatorKey: GlobalKey(), + home: Scaffold( + body: SetFormWidget(day), + ), + ), + ), ); } diff --git a/test_data/gallery.dart b/test_data/gallery.dart index dd69a114..5d18d14d 100644 --- a/test_data/gallery.dart +++ b/test_data/gallery.dart @@ -47,6 +47,6 @@ List getTestImages() { 'https://raw.githubusercontent.com/wger-project/flutter/master/fastlane/metadata/android/en-US/images/phoneScreenshots/06%20-%20weight.png', description: '', date: DateTime(2021, 2, 22), - ) + ), ]; } diff --git a/test_data/screenshots_exercises.dart b/test_data/screenshots_exercises.dart index c9663f5d..743474bc 100644 --- a/test_data/screenshots_exercises.dart +++ b/test_data/screenshots_exercises.dart @@ -202,7 +202,7 @@ final squatsTranslations = [ squatsEN, squatsEL, squatsAR, - squatsZH + squatsZH, ]; final benchPressDE = Translation( @@ -492,7 +492,7 @@ final crunchesTranslations = [ crunchesRU, crunchesHE, crunchesAR, - crunchesZH + crunchesZH, ]; final curlsEN = Translation( From 85c245d67d24064142ed5fa7555672049bb86628 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 18 Sep 2024 15:57:10 +0300 Subject: [PATCH 3/7] dcm fix --only-rules=unnecessary-trailing-comma lib test test_data --- lib/widgets/nutrition/nutrition_tiles.dart | 5 +- .../exercise_provider_load_test.dart | 8 +- test/exercises/exercise_provider_test.dart | 5 +- .../exercises_detail_widget_test.dart | 4 +- test/gallery/gallery_form_test.dart | 4 +- test/gallery/gallery_screen_test.dart | 4 +- .../nutrition/nutritional_meal_form_test.dart | 4 +- .../nutrition/nutritional_plan_form_test.dart | 4 +- .../nutritional_plan_screen_test.dart | 8 +- .../nutritional_plans_screen_test.dart | 10 +-- test/weight/weight_form_test.dart | 4 +- test/weight/weight_screen_test.dart | 4 +- .../repetition_unit_form_widget_test.dart | 4 +- .../workout/weight_unit_form_widget_test.dart | 4 +- test/workout/workout_day_form_test.dart | 4 +- test/workout/workout_form_test.dart | 4 +- test/workout/workout_plans_screen_test.dart | 4 +- test/workout/workout_provider_test.dart | 8 +- test/workout/workout_set_form_test.dart | 8 +- test_data/nutritional_plans.dart | 15 +--- test_data/screenshots_exercises.dart | 78 ++++--------------- test_data/workouts.dart | 14 +--- 22 files changed, 43 insertions(+), 164 deletions(-) diff --git a/lib/widgets/nutrition/nutrition_tiles.dart b/lib/widgets/nutrition/nutrition_tiles.dart index dc23fbff..304ef9f3 100644 --- a/lib/widgets/nutrition/nutrition_tiles.dart +++ b/lib/widgets/nutrition/nutrition_tiles.dart @@ -32,10 +32,7 @@ class MealItemValuesTile extends StatelessWidget { trailing: IconButton( icon: const Icon(Icons.info_outline), onPressed: () { - showIngredientDetails( - context, - ingredient.id, - ); + showIngredientDetails(context, ingredient.id); }, ), ); diff --git a/test/exercises/exercise_provider_load_test.dart b/test/exercises/exercise_provider_load_test.dart index bc809b5c..7123cba7 100644 --- a/test/exercises/exercise_provider_load_test.dart +++ b/test/exercises/exercise_provider_load_test.dart @@ -54,12 +54,8 @@ void main() { provider.languages = [tLanguage1, tLanguage2, tLanguage3]; // Mock base info response - when( - mockBaseProvider.makeUrl(exerciseBaseInfoUrl, id: 9), - ).thenReturn(tExerciseBaseInfoUri); - when( - mockBaseProvider.makeUrl(exerciseBaseInfoUrl, id: 1), - ).thenReturn(tExerciseBaseInfoUri2); + when(mockBaseProvider.makeUrl(exerciseBaseInfoUrl, id: 9)).thenReturn(tExerciseBaseInfoUri); + when(mockBaseProvider.makeUrl(exerciseBaseInfoUrl, id: 1)).thenReturn(tExerciseBaseInfoUri2); when(mockBaseProvider.fetch(tExerciseBaseInfoUri)) .thenAnswer((_) => Future.value(tExerciseInfoMap)); diff --git a/test/exercises/exercise_provider_test.dart b/test/exercises/exercise_provider_test.dart index 0170a3fe..5a24bf43 100644 --- a/test/exercises/exercise_provider_test.dart +++ b/test/exercises/exercise_provider_test.dart @@ -236,10 +236,7 @@ void main() { // assert verifyNever(provider.baseProvider.fetch(tSearchByNameUri)); - expect( - provider.filteredExercises, - data.getTestExercises(), - ); + expect(provider.filteredExercises, data.getTestExercises()); }); test('A muscle is selected with no search term. Should find results', () async { diff --git a/test/exercises/exercises_detail_widget_test.dart b/test/exercises/exercises_detail_widget_test.dart index 12e98ba0..d40dd857 100644 --- a/test/exercises/exercises_detail_widget_test.dart +++ b/test/exercises/exercises_detail_widget_test.dart @@ -37,9 +37,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, navigatorKey: GlobalKey(), - home: Scaffold( - body: ExerciseDetail(getTestExercises()[0]), - ), + home: Scaffold(body: ExerciseDetail(getTestExercises()[0])), ), ); } diff --git a/test/gallery/gallery_form_test.dart b/test/gallery/gallery_form_test.dart index fcf26cf7..6fdc69e0 100644 --- a/test/gallery/gallery_form_test.dart +++ b/test/gallery/gallery_form_test.dart @@ -46,9 +46,7 @@ void main() { locale: Locale(locale), localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, - home: Scaffold( - body: useImage ? ImageForm(image) : ImageForm(), - ), + home: Scaffold(body: useImage ? ImageForm(image) : ImageForm()), ), ); } diff --git a/test/gallery/gallery_screen_test.dart b/test/gallery/gallery_screen_test.dart index 848aeeb9..0f796ab1 100644 --- a/test/gallery/gallery_screen_test.dart +++ b/test/gallery/gallery_screen_test.dart @@ -48,9 +48,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, home: const Gallery(), - routes: { - FormScreen.routeName: (ctx) => const FormScreen(), - }, + routes: {FormScreen.routeName: (ctx) => const FormScreen()}, ), ); } diff --git a/test/nutrition/nutritional_meal_form_test.dart b/test/nutrition/nutritional_meal_form_test.dart index 8d25f6c0..fdb781f6 100644 --- a/test/nutrition/nutritional_meal_form_test.dart +++ b/test/nutrition/nutritional_meal_form_test.dart @@ -60,9 +60,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, navigatorKey: key, - home: Scaffold( - body: MealForm(1, meal), - ), + home: Scaffold(body: MealForm(1, meal)), routes: { NutritionalPlanScreen.routeName: (ctx) => const NutritionalPlanScreen(), }, diff --git a/test/nutrition/nutritional_plan_form_test.dart b/test/nutrition/nutritional_plan_form_test.dart index 0eb990fc..e366ef51 100644 --- a/test/nutrition/nutritional_plan_form_test.dart +++ b/test/nutrition/nutritional_plan_form_test.dart @@ -58,9 +58,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, navigatorKey: key, - home: Scaffold( - body: PlanForm(plan), - ), + home: Scaffold(body: PlanForm(plan)), routes: { NutritionalPlanScreen.routeName: (ctx) => const NutritionalPlanScreen(), }, diff --git a/test/nutrition/nutritional_plan_screen_test.dart b/test/nutrition/nutritional_plan_screen_test.dart index 563ac86f..f9a5b45b 100644 --- a/test/nutrition/nutritional_plan_screen_test.dart +++ b/test/nutrition/nutritional_plan_screen_test.dart @@ -72,13 +72,9 @@ void main() { await loadAppFonts(); final globalKey = GlobalKey(); await tester.pumpWidgetBuilder( - Material( - key: globalKey, - ), + Material(key: globalKey), wrapper: materialAppWrapper( - localizations: [ - AppLocalizations.delegate, - ], + localizations: [AppLocalizations.delegate], ), surfaceSize: const Size(500, 1000), ); diff --git a/test/nutrition/nutritional_plans_screen_test.dart b/test/nutrition/nutritional_plans_screen_test.dart index 697f4d21..2ba4dbac 100644 --- a/test/nutrition/nutritional_plans_screen_test.dart +++ b/test/nutrition/nutritional_plans_screen_test.dart @@ -40,10 +40,8 @@ void main() { final client = MockClient(); Widget createHomeScreen({locale = 'en'}) { - when(client.delete( - any, - headers: anyNamed('headers'), - )).thenAnswer((_) async => http.Response('', 200)); + when(client.delete(any, headers: anyNamed('headers'))) + .thenAnswer((_) async => http.Response('', 200)); when(mockBaseProvider.deleteRequest(any, any)).thenAnswer( (_) async => http.Response('', 200), @@ -74,9 +72,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, home: const NutritionalPlansScreen(), - routes: { - FormScreen.routeName: (ctx) => const FormScreen(), - }, + routes: {FormScreen.routeName: (ctx) => const FormScreen()}, ), ); } diff --git a/test/weight/weight_form_test.dart b/test/weight/weight_form_test.dart index e8402869..7c81ef7e 100644 --- a/test/weight/weight_form_test.dart +++ b/test/weight/weight_form_test.dart @@ -30,9 +30,7 @@ void main() { locale: Locale(locale), localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, - home: Scaffold( - body: WeightForm(weightEntry), - ), + home: Scaffold(body: WeightForm(weightEntry)), ); } diff --git a/test/weight/weight_screen_test.dart b/test/weight/weight_screen_test.dart index 8dbe640c..fcebe260 100644 --- a/test/weight/weight_screen_test.dart +++ b/test/weight/weight_screen_test.dart @@ -65,9 +65,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, home: const WeightScreen(), - routes: { - FormScreen.routeName: (_) => const FormScreen(), - }, + routes: {FormScreen.routeName: (_) => const FormScreen()}, ), ), ), diff --git a/test/workout/repetition_unit_form_widget_test.dart b/test/workout/repetition_unit_form_widget_test.dart index 5e250bd7..42386007 100644 --- a/test/workout/repetition_unit_form_widget_test.dart +++ b/test/workout/repetition_unit_form_widget_test.dart @@ -64,9 +64,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, navigatorKey: key, - home: Scaffold( - body: RepetitionUnitInputWidget(setting1), - ), + home: Scaffold(body: RepetitionUnitInputWidget(setting1)), routes: { WorkoutPlanScreen.routeName: (ctx) => const WorkoutPlanScreen(), }, diff --git a/test/workout/weight_unit_form_widget_test.dart b/test/workout/weight_unit_form_widget_test.dart index 4b564383..ed68f044 100644 --- a/test/workout/weight_unit_form_widget_test.dart +++ b/test/workout/weight_unit_form_widget_test.dart @@ -65,9 +65,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, navigatorKey: key, - home: Scaffold( - body: WeightUnitInputWidget(setting1), - ), + home: Scaffold(body: WeightUnitInputWidget(setting1)), routes: { WorkoutPlanScreen.routeName: (ctx) => const WorkoutPlanScreen(), }, diff --git a/test/workout/workout_day_form_test.dart b/test/workout/workout_day_form_test.dart index 99e321e9..ef466062 100644 --- a/test/workout/workout_day_form_test.dart +++ b/test/workout/workout_day_form_test.dart @@ -51,9 +51,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, navigatorKey: key, - home: Scaffold( - body: DayFormWidget(workoutPlan), - ), + home: Scaffold(body: DayFormWidget(workoutPlan)), ), ); } diff --git a/test/workout/workout_form_test.dart b/test/workout/workout_form_test.dart index a3ddd7f4..7528c09f 100644 --- a/test/workout/workout_form_test.dart +++ b/test/workout/workout_form_test.dart @@ -59,9 +59,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, navigatorKey: key, - home: Scaffold( - body: WorkoutForm(workoutPlan), - ), + home: Scaffold(body: WorkoutForm(workoutPlan)), routes: { WorkoutPlanScreen.routeName: (ctx) => const WorkoutPlanScreen(), }, diff --git a/test/workout/workout_plans_screen_test.dart b/test/workout/workout_plans_screen_test.dart index 993eb9a6..ebc8095b 100644 --- a/test/workout/workout_plans_screen_test.dart +++ b/test/workout/workout_plans_screen_test.dart @@ -71,9 +71,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, home: const WorkoutPlansScreen(), - routes: { - FormScreen.routeName: (ctx) => const FormScreen(), - }, + routes: {FormScreen.routeName: (ctx) => const FormScreen()}, ), ); } diff --git a/test/workout/workout_provider_test.dart b/test/workout/workout_provider_test.dart index 1bcb7d4f..d6a17e4e 100644 --- a/test/workout/workout_provider_test.dart +++ b/test/workout/workout_provider_test.dart @@ -51,9 +51,7 @@ void main() { final uri = Uri.https('localhost', 'api/v2/workout/325397/'); when(mockBaseProvider.makeUrl('workout', id: 325397)).thenReturn(uri); - when(mockBaseProvider.fetch( - uri, - )).thenAnswer( + when(mockBaseProvider.fetch(uri)).thenAnswer( (_) async => Future.value({ 'id': 325397, 'name': 'Test workout', @@ -78,9 +76,7 @@ void main() { final exercisesProvider = ExercisesProvider(mockBaseProvider); final uri = Uri.https('localhost', 'api/v2/workout/325397/'); when(mockBaseProvider.makeUrl('workout', id: 325397)).thenReturn(uri); - when(mockBaseProvider.fetch( - uri, - )).thenAnswer( + when(mockBaseProvider.fetch(uri)).thenAnswer( (_) async => Future.value({ 'id': 325397, 'name': 'Test workout', diff --git a/test/workout/workout_set_form_test.dart b/test/workout/workout_set_form_test.dart index 50479298..08961854 100644 --- a/test/workout/workout_set_form_test.dart +++ b/test/workout/workout_set_form_test.dart @@ -63,9 +63,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, navigatorKey: GlobalKey(), - home: Scaffold( - body: SetFormWidget(day), - ), + home: Scaffold(body: SetFormWidget(day)), ), ), ); @@ -90,9 +88,7 @@ void main() { any, languageCode: anyNamed('languageCode'), searchEnglish: anyNamed('searchEnglish'), - )).thenAnswer( - (_) => Future.value([getTestExercises().first]), - ); + )).thenAnswer((_) => Future.value([getTestExercises().first])); await tester.pumpWidget(createHomeScreen()); await tester.pumpAndSettle(); diff --git a/test_data/nutritional_plans.dart b/test_data/nutritional_plans.dart index 5e77e792..1b3a42cc 100644 --- a/test_data/nutritional_plans.dart +++ b/test_data/nutritional_plans.dart @@ -146,22 +146,13 @@ final cake = Ingredient( ); NutritionalPlan getNutritionalPlan() { - final mealItem1 = MealItem( - ingredientId: 1, - amount: 100, - ); + final mealItem1 = MealItem(ingredientId: 1, amount: 100); mealItem1.ingredient = ingredient1; - final mealItem2 = MealItem( - ingredientId: 2, - amount: 75, - ); + final mealItem2 = MealItem(ingredientId: 2, amount: 75); mealItem2.ingredient = ingredient2; - final mealItem3 = MealItem( - ingredientId: 3, - amount: 300, - ); + final mealItem3 = MealItem(ingredientId: 3, amount: 300); mealItem3.ingredient = ingredient3; final meal1 = Meal( diff --git a/test_data/screenshots_exercises.dart b/test_data/screenshots_exercises.dart index 743474bc..a801bd59 100644 --- a/test_data/screenshots_exercises.dart +++ b/test_data/screenshots_exercises.dart @@ -2,86 +2,34 @@ import 'package:wger/models/exercises/language.dart'; import 'package:wger/models/exercises/translation.dart'; -const tLanguage21 = Language( - id: 21, - shortName: 'he', - fullName: 'עברית', -); -const tLanguage5 = Language( - id: 5, - shortName: 'ru', - fullName: 'Русский', -); -const tLanguage16 = Language( - id: 16, - shortName: 'tr', - fullName: 'Türkçe', -); +const tLanguage21 = Language(id: 21, shortName: 'he', fullName: 'עברית'); +const tLanguage5 = Language(id: 5, shortName: 'ru', fullName: 'Русский'); +const tLanguage16 = Language(id: 16, shortName: 'tr', fullName: 'Türkçe'); const tLanguage22 = Language( id: 22, shortName: 'hr', fullName: 'Hrvatski jezik', ); -const tLanguage9 = Language( - id: 9, - shortName: 'cs', - fullName: 'Čeština', -); -const tLanguage4 = Language( - id: 4, - shortName: 'es', - fullName: 'Español', -); -const tLanguage24 = Language( - id: 24, - shortName: 'zh', - fullName: '漢語', -); +const tLanguage9 = Language(id: 9, shortName: 'cs', fullName: 'Čeština'); +const tLanguage4 = Language(id: 4, shortName: 'es', fullName: 'Español'); +const tLanguage24 = Language(id: 24, shortName: 'zh', fullName: '漢語'); const tLanguage17 = Language( id: 17, shortName: 'ar', fullName: 'اَللُّغَةُ اَلْعَرَبِيَّة', ); -const tLanguage8 = Language( - id: 8, - shortName: 'el', - fullName: 'Ελληνικά', -); -const tLanguage2 = Language( - id: 2, - shortName: 'en', - fullName: 'English', -); -const tLanguage13 = Language( - id: 13, - shortName: 'it', - fullName: 'Italian', -); -const tLanguage12 = Language( - id: 12, - shortName: 'fr', - fullName: 'Français', -); -const tLanguage1 = Language( - id: 1, - shortName: 'de', - fullName: 'Deutsch', -); +const tLanguage8 = Language(id: 8, shortName: 'el', fullName: 'Ελληνικά'); +const tLanguage2 = Language(id: 2, shortName: 'en', fullName: 'English'); +const tLanguage13 = Language(id: 13, shortName: 'it', fullName: 'Italian'); +const tLanguage12 = Language(id: 12, shortName: 'fr', fullName: 'Français'); +const tLanguage1 = Language(id: 1, shortName: 'de', fullName: 'Deutsch'); const tLanguage23 = Language( id: 23, shortName: 'id', fullName: 'Bahasa Indonesia', ); -const tLanguage6 = Language( - id: 6, - shortName: 'nl', - fullName: 'Nederlands', -); -const tLanguage7 = Language( - id: 7, - shortName: 'pt', - fullName: 'Português', -); +const tLanguage6 = Language(id: 6, shortName: 'nl', fullName: 'Nederlands'); +const tLanguage7 = Language(id: 7, shortName: 'pt', fullName: 'Português'); final squatsPT = Translation( id: 1598, diff --git a/test_data/workouts.dart b/test_data/workouts.dart index ecd36a31..2491c50d 100644 --- a/test_data/workouts.dart +++ b/test_data/workouts.dart @@ -110,12 +110,7 @@ WorkoutPlan getWorkout({List? exercises}) { settingSquat.exercise = testBases[4]; settingSquat.weight = 120; - final setSquat = Set.withData( - id: 2, - day: 1, - sets: 3, - order: 1, - ); + final setSquat = Set.withData(id: 2, day: 1, sets: 3, order: 1); setSquat.addExerciseBase(testBases[4]); setSquat.settings.add(settingSquat); setSquat.settingsComputed = [settingSquat, settingSquat]; @@ -135,12 +130,7 @@ WorkoutPlan getWorkout({List? exercises}) { settingSideRaises.exercise = testBases[5]; settingSideRaises.weight = 6; - final setSideRaises = Set.withData( - id: 3, - day: 1, - sets: 3, - order: 1, - ); + final setSideRaises = Set.withData(id: 3, day: 1, sets: 3, order: 1); setSideRaises.addExerciseBase(testBases[5]); setSideRaises.settings.add(settingSideRaises); setSideRaises.settingsComputed = [settingSideRaises, settingSideRaises]; From 2fb3d675b29db38f613e8a87e09b803d245e20c3 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 18 Sep 2024 21:08:47 +0300 Subject: [PATCH 4/7] ignore avoid-passing-async-when-sync-expected --- analysis_options.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/analysis_options.yaml b/analysis_options.yaml index 1ff2f92e..8585a974 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -163,6 +163,8 @@ dart_code_metrics: - prefer-prefixed-global-constants: false # we don't really care for the 'k' prefix - prefer-single-widget-per-file: false - avoid-passing-self-as-argument: false # fairly harmless. and e.g. drift calls are like this + - avoid-passing-async-when-sync-expected: false # we really like to do this in onTap() etc, and it seems harmless + formatter: indent: 0 line-length: 100 From 25ad580a386ff4a9cdc3a296773bc595ec4ac463 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 18 Sep 2024 21:23:18 +0300 Subject: [PATCH 5/7] disable prefer-match-file-name for now.. --- analysis_options.yaml | 1 + lib/models/nutrition/ingredient.dart | 2 +- lib/models/nutrition/{image.dart => ingredient_image.dart} | 2 +- lib/models/nutrition/{image.g.dart => ingredient_image.g.dart} | 2 +- lib/providers/nutrition.dart | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) rename lib/models/nutrition/{image.dart => ingredient_image.dart} (98%) rename lib/models/nutrition/{image.g.dart => ingredient_image.g.dart} (98%) diff --git a/analysis_options.yaml b/analysis_options.yaml index 8585a974..15127111 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -164,6 +164,7 @@ dart_code_metrics: - prefer-single-widget-per-file: false - avoid-passing-self-as-argument: false # fairly harmless. and e.g. drift calls are like this - avoid-passing-async-when-sync-expected: false # we really like to do this in onTap() etc, and it seems harmless + - prefer-match-file-name: false # dieter wants to enable this. but requires a lot of renames. what does roland think? formatter: indent: 0 diff --git a/lib/models/nutrition/ingredient.dart b/lib/models/nutrition/ingredient.dart index a8d4b565..eb3bcf9a 100644 --- a/lib/models/nutrition/ingredient.dart +++ b/lib/models/nutrition/ingredient.dart @@ -17,7 +17,7 @@ */ import 'package:json_annotation/json_annotation.dart'; import 'package:wger/helpers/json.dart'; -import 'package:wger/models/nutrition/image.dart'; +import 'package:wger/models/nutrition/ingredient_image.dart'; import 'package:wger/models/nutrition/nutritional_values.dart'; part 'ingredient.g.dart'; diff --git a/lib/models/nutrition/image.dart b/lib/models/nutrition/ingredient_image.dart similarity index 98% rename from lib/models/nutrition/image.dart rename to lib/models/nutrition/ingredient_image.dart index bc23f0e4..30983bfb 100644 --- a/lib/models/nutrition/image.dart +++ b/lib/models/nutrition/ingredient_image.dart @@ -17,7 +17,7 @@ */ import 'package:json_annotation/json_annotation.dart'; -part 'image.g.dart'; +part 'ingredient_image.g.dart'; @JsonSerializable() class IngredientImage { diff --git a/lib/models/nutrition/image.g.dart b/lib/models/nutrition/ingredient_image.g.dart similarity index 98% rename from lib/models/nutrition/image.g.dart rename to lib/models/nutrition/ingredient_image.g.dart index cc380f68..558217ee 100644 --- a/lib/models/nutrition/image.g.dart +++ b/lib/models/nutrition/ingredient_image.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'image.dart'; +part of 'ingredient_image.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index 9c88eee7..a505f800 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -25,8 +25,8 @@ import 'package:wger/exceptions/http_exception.dart'; import 'package:wger/exceptions/no_such_entry_exception.dart'; import 'package:wger/helpers/consts.dart'; import 'package:wger/models/exercises/ingredient_api.dart'; -import 'package:wger/models/nutrition/image.dart'; import 'package:wger/models/nutrition/ingredient.dart'; +import 'package:wger/models/nutrition/ingredient_image.dart'; import 'package:wger/models/nutrition/log.dart'; import 'package:wger/models/nutrition/meal.dart'; import 'package:wger/models/nutrition/meal_item.dart'; From 7e6c78c5e3f86cf003c921b2a61b30cac6c770c4 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 18 Sep 2024 21:29:22 +0300 Subject: [PATCH 6/7] dart fix --apply --- lib/widgets/dashboard/widgets.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widgets/dashboard/widgets.dart b/lib/widgets/dashboard/widgets.dart index d1060ec5..e772dc2d 100644 --- a/lib/widgets/dashboard/widgets.dart +++ b/lib/widgets/dashboard/widgets.dart @@ -194,7 +194,7 @@ class _DashboardWeightWidgetState extends State { MeasurementOverallChangeWidget( entries7dAvg.first, entries7dAvg.last, - weightUnit(profile!.isMetric, context), + weightUnit(profile.isMetric, context), ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, From f90609f147e14dca1969c5ea92f0fcabc26cb578 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 18 Sep 2024 21:40:00 +0300 Subject: [PATCH 7/7] various dcm cleanups --- lib/models/nutrition/nutritional_goals.dart | 1 + lib/screens/nutritional_plan_screen.dart | 31 ++++++++++--------- lib/screens/nutritional_plans_screen.dart | 2 +- lib/widgets/nutrition/charts.dart | 23 ++++++-------- lib/widgets/nutrition/forms.dart | 13 ++++---- lib/widgets/nutrition/helpers.dart | 2 +- lib/widgets/nutrition/ingredient_dialogs.dart | 19 +++++++----- .../nutritional_meal_item_form_test.dart | 7 ----- 8 files changed, 47 insertions(+), 51 deletions(-) diff --git a/lib/models/nutrition/nutritional_goals.dart b/lib/models/nutrition/nutritional_goals.dart index 59cdf33b..7a668a46 100644 --- a/lib/models/nutrition/nutritional_goals.dart +++ b/lib/models/nutrition/nutritional_goals.dart @@ -134,6 +134,7 @@ class NutritionalGoals { @override String toString() { + // ignore: avoid-nullable-interpolation return 'e: $energy, p: $protein, c: $carbohydrates, cS: $carbohydratesSugar, f: $fat, fS: $fatSaturated, fi: $fiber, s: $sodium'; } diff --git a/lib/screens/nutritional_plan_screen.dart b/lib/screens/nutritional_plan_screen.dart index bb13be6c..6d695a29 100644 --- a/lib/screens/nutritional_plan_screen.dart +++ b/lib/screens/nutritional_plan_screen.dart @@ -112,20 +112,23 @@ class NutritionalPlanScreen extends StatelessWidget { PopupMenuButton( icon: const Icon(Icons.more_vert, color: appBarForeground), onSelected: (value) { - if (value == NutritionalPlanOptions.edit) { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).edit, - PlanForm(nutritionalPlan), - hasListView: true, - ), - ); - } else if (value == NutritionalPlanOptions.delete) { - Provider.of(context, listen: false) - .deletePlan(nutritionalPlan.id!); - Navigator.of(context).pop(); + switch (value) { + case NutritionalPlanOptions.edit: + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).edit, + PlanForm(nutritionalPlan), + hasListView: true, + ), + ); + break; + case NutritionalPlanOptions.delete: + Provider.of(context, listen: false) + .deletePlan(nutritionalPlan.id!); + Navigator.of(context).pop(); + break; } }, itemBuilder: (BuildContext context) { diff --git a/lib/screens/nutritional_plans_screen.dart b/lib/screens/nutritional_plans_screen.dart index b3ed56b3..43ce024c 100644 --- a/lib/screens/nutritional_plans_screen.dart +++ b/lib/screens/nutritional_plans_screen.dart @@ -35,7 +35,7 @@ class NutritionalPlansScreen extends StatelessWidget { appBar: EmptyAppBar(AppLocalizations.of(context).nutritionalPlans), floatingActionButton: FloatingActionButton( child: const Icon(Icons.add, color: Colors.white), - onPressed: () async { + onPressed: () { Navigator.pushNamed( context, FormScreen.routeName, diff --git a/lib/widgets/nutrition/charts.dart b/lib/widgets/nutrition/charts.dart index 32c558e1..c429f0a8 100644 --- a/lib/widgets/nutrition/charts.dart +++ b/lib/widgets/nutrition/charts.dart @@ -26,18 +26,6 @@ import 'package:wger/models/nutrition/nutritional_plan.dart'; import 'package:wger/models/nutrition/nutritional_values.dart'; import 'package:wger/widgets/measurements/charts.dart'; -class FlNutritionalPlanGoalWidget extends StatefulWidget { - const FlNutritionalPlanGoalWidget({ - super.key, - required NutritionalPlan nutritionalPlan, - }) : _nutritionalPlan = nutritionalPlan; - - final NutritionalPlan _nutritionalPlan; - - @override - State createState() => FlNutritionalPlanGoalWidgetState(); -} - // * fl_chart doesn't support horizontal bar charts yet. // see https://github.com/imaNNeo/fl_chart/issues/113 // even if it did, i doubt it would let us put text between the gauges/bars @@ -45,7 +33,14 @@ class FlNutritionalPlanGoalWidget extends StatefulWidget { // using multiple colors to show multiple components such as surplus, deficit // * here we draw our own simple gauges that can go beyond 100%, // and support multiple segments -class FlNutritionalPlanGoalWidgetState extends State { +class FlNutritionalPlanGoalWidget extends StatelessWidget { + const FlNutritionalPlanGoalWidget({ + super.key, + required NutritionalPlan nutritionalPlan, + }) : _nutritionalPlan = nutritionalPlan; + + final NutritionalPlan _nutritionalPlan; + // normWidth is the width representing 100% completion // note that if val > plan, we will draw beyond this width // therefore, caller must set this width to accommodate surpluses. @@ -91,7 +86,7 @@ class FlNutritionalPlanGoalWidgetState extends State { style: const TextStyle(color: Colors.red), ), ); - } else { - return const SizedBox( - width: 20, - height: 20, - child: CircularProgressIndicator(), - ); } + return const SizedBox( + width: 20, + height: 20, + child: CircularProgressIndicator(), + ); }, ), ], @@ -394,7 +393,7 @@ class IngredientFormState extends State { ElevatedButton( key: const Key(SUBMIT_BUTTON_KEY_NAME), child: Text(AppLocalizations.of(context).save), - onPressed: () async { + onPressed: () { if (!_form.currentState!.validate()) { return; } diff --git a/lib/widgets/nutrition/helpers.dart b/lib/widgets/nutrition/helpers.dart index f4f6d3f7..b60661fb 100644 --- a/lib/widgets/nutrition/helpers.dart +++ b/lib/widgets/nutrition/helpers.dart @@ -105,7 +105,7 @@ void showIngredientDetails(BuildContext context, int id, {void Function()? selec builder: (context) => FutureBuilder( future: Provider.of(context, listen: false).fetchIngredient(id), builder: (BuildContext context, AsyncSnapshot snapshot) { - return IngredientDetails(snapshot, select: select); + return IngredientDetails(snapshot, onSelect: select); }, ), ); diff --git a/lib/widgets/nutrition/ingredient_dialogs.dart b/lib/widgets/nutrition/ingredient_dialogs.dart index e636e22c..b5fcde09 100644 --- a/lib/widgets/nutrition/ingredient_dialogs.dart +++ b/lib/widgets/nutrition/ingredient_dialogs.dart @@ -21,8 +21,8 @@ Widget ingredientImage(String url, BuildContext context) { class IngredientDetails extends StatelessWidget { final AsyncSnapshot snapshot; - final void Function()? select; - const IngredientDetails(this.snapshot, {super.key, this.select}); + final void Function()? onSelect; + const IngredientDetails(this.snapshot, {super.key, this.onSelect}); @override Widget build(BuildContext context) { @@ -76,12 +76,12 @@ class IngredientDetails extends StatelessWidget { ), ), actions: [ - if (snapshot.hasData && select != null) + if (snapshot.hasData && onSelect != null) TextButton( key: const Key('ingredient-details-continue-button'), child: Text(MaterialLocalizations.of(context).continueButtonLabel), onPressed: () { - select!(); + onSelect!(); Navigator.of(context).pop(); }, ), @@ -100,9 +100,14 @@ class IngredientDetails extends StatelessWidget { class IngredientScanResultDialog extends StatelessWidget { final AsyncSnapshot snapshot; final String barcode; - final Function(int id, String name, num? amount) selectIngredient; + final Function(int id, String name, num? amount) onSelectIngredient; - const IngredientScanResultDialog(this.snapshot, this.barcode, this.selectIngredient, {super.key}); + const IngredientScanResultDialog( + this.snapshot, + this.barcode, + this.onSelectIngredient, { + super.key, + }); @override Widget build(BuildContext context) { @@ -181,7 +186,7 @@ class IngredientScanResultDialog extends StatelessWidget { key: const Key('ingredient-scan-result-dialog-confirm-button'), child: Text(MaterialLocalizations.of(context).continueButtonLabel), onPressed: () { - selectIngredient(ingredient!.id, ingredient.name, null); + onSelectIngredient(ingredient!.id, ingredient.name, null); Navigator.of(context).pop(); }, ), diff --git a/test/nutrition/nutritional_meal_item_form_test.dart b/test/nutrition/nutritional_meal_item_form_test.dart index fddca2b3..e37435e9 100644 --- a/test/nutrition/nutritional_meal_item_form_test.dart +++ b/test/nutrition/nutritional_meal_item_form_test.dart @@ -21,7 +21,6 @@ import 'package:wger/widgets/nutrition/forms.dart'; import '../../test_data/nutritional_plans.dart'; import '../fixtures/fixture_reader.dart'; -import '../measurements/measurement_provider_test.mocks.dart'; import '../other/base_provider_test.mocks.dart'; import 'nutritional_plan_form_test.mocks.dart'; @@ -44,15 +43,9 @@ void main() { sodium: 0.5, ); - late MockWgerBaseProvider mockWgerBaseProvider; - var mockNutrition = MockNutritionPlansProvider(); final client = MockClient(); - setUp(() { - mockWgerBaseProvider = MockWgerBaseProvider(); - }); - var plan1 = NutritionalPlan.empty(); var meal1 = Meal();