From cce0b94edc79e23eb62e68fb51ea8b6fef228f9f Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Fri, 23 May 2025 18:44:29 +0200 Subject: [PATCH] Cleanup --- .vscode/settings.json | 3 +- lib/helpers/exercises/plate_configurator.dart | 13 -------- lib/main.dart | 32 +++++++++---------- lib/providers/user.dart | 16 +++++----- test/core/settings_test.mocks.dart | 10 ------ .../contribute_exercise_test.mocks.dart | 10 ------ .../plate_calculator_test.mocks.dart | 2 +- test/routine/gym_mode_screen_test.dart | 4 +++ test/weight/weight_screen_test.mocks.dart | 10 ------ 9 files changed, 30 insertions(+), 70 deletions(-) delete mode 100644 lib/helpers/exercises/plate_configurator.dart diff --git a/.vscode/settings.json b/.vscode/settings.json index 585ffee3..a318ce4a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,4 @@ { "dart.lineLength": 100, - "diffEditor.ignoreTrimWhitespace": true, - "cmake.sourceDirectory": "/Users/ayush/flutter/linux", + "diffEditor.ignoreTrimWhitespace": true } diff --git a/lib/helpers/exercises/plate_configurator.dart b/lib/helpers/exercises/plate_configurator.dart deleted file mode 100644 index 64cc584c..00000000 --- a/lib/helpers/exercises/plate_configurator.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:flutter/material.dart'; - -class PlateConfiguration extends ChangeNotifier { - //olympic standard weights - List _plateWeights = [1.25, 2.5, 5, 10, 15, 20, 25]; - - List get plateWeights => _plateWeights; - - void setPlateWeights(List weights) { - _plateWeights = weights; - notifyListeners(); - } -} diff --git a/lib/main.dart b/lib/main.dart index 314d90e4..43a7de6f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -90,20 +90,20 @@ void main() async { await PreferenceHelper.instance.migrationSupportFunctionForSharedPreferences(); // Catch errors from Flutter itself (widget build, layout, paint, etc.) - // FlutterError.onError = (FlutterErrorDetails details) { - // final stack = details.stack ?? StackTrace.empty; - // if (kDebugMode) { - // FlutterError.dumpErrorToConsole(details); - // } - // - // // Don't show the full error dialog for network image loading errors. - // if (details.exception is NetworkImageLoadException) { - // return; - // } - // - // // showGeneralErrorDialog(details.exception, stack); - // throw details.exception; - // }; + FlutterError.onError = (FlutterErrorDetails details) { + final stack = details.stack ?? StackTrace.empty; + if (kDebugMode) { + FlutterError.dumpErrorToConsole(details); + } + + // Don't show the full error dialog for network image loading errors. + if (details.exception is NetworkImageLoadException) { + return; + } + + showGeneralErrorDialog(details.exception, stack); + // throw details.exception; + }; // Catch errors that happen outside of the Flutter framework (e.g., in async operations) PlatformDispatcher.instance.onError = (error, stack) { @@ -114,8 +114,8 @@ void main() async { if (error is WgerHttpException) { showHttpExceptionErrorDialog(error); } else { - // showGeneralErrorDialog(error, stack); - throw error; + showGeneralErrorDialog(error, stack); + // throw error; } // Return true to indicate that the error has been handled. diff --git a/lib/providers/user.dart b/lib/providers/user.dart index f6a271e2..fc8959d1 100644 --- a/lib/providers/user.dart +++ b/lib/providers/user.dart @@ -45,14 +45,14 @@ class UserProvider with ChangeNotifier { profile = null; } - // change the unit of plates - void changeUnit({changeTo = 'kg'}) { - if (changeTo == 'kg') { - profile?.weightUnitStr = 'lb'; - } else { - profile?.weightUnitStr = 'kg'; - } - } + // // change the unit of plates + // void changeUnit({changeTo = 'kg'}) { + // if (changeTo == 'kg') { + // profile?.weightUnitStr = 'lb'; + // } else { + // profile?.weightUnitStr = 'kg'; + // } + // } // Load theme mode from SharedPreferences Future _loadThemeMode() async { diff --git a/test/core/settings_test.mocks.dart b/test/core/settings_test.mocks.dart index 52c09767..e5cc01bd 100644 --- a/test/core/settings_test.mocks.dart +++ b/test/core/settings_test.mocks.dart @@ -1180,16 +1180,6 @@ class MockUserProvider extends _i1.Mock implements _i22.UserProvider { returnValueForMissingStub: null, ); - @override - void changeUnit({dynamic changeTo = 'kg'}) => super.noSuchMethod( - Invocation.method( - #changeUnit, - [], - {#changeTo: changeTo}, - ), - returnValueForMissingStub: null, - ); - @override void setThemeMode(_i23.ThemeMode? mode) => super.noSuchMethod( Invocation.method( diff --git a/test/exercises/contribute_exercise_test.mocks.dart b/test/exercises/contribute_exercise_test.mocks.dart index 7bcbeaf7..41cf8eff 100644 --- a/test/exercises/contribute_exercise_test.mocks.dart +++ b/test/exercises/contribute_exercise_test.mocks.dart @@ -592,16 +592,6 @@ class MockUserProvider extends _i1.Mock implements _i17.UserProvider { returnValueForMissingStub: null, ); - @override - void changeUnit({dynamic changeTo = 'kg'}) => super.noSuchMethod( - Invocation.method( - #changeUnit, - [], - {#changeTo: changeTo}, - ), - returnValueForMissingStub: null, - ); - @override void setThemeMode(_i18.ThemeMode? mode) => super.noSuchMethod( Invocation.method( diff --git a/test/providers/plate_calculator_test.mocks.dart b/test/providers/plate_calculator_test.mocks.dart index df2e0a09..31e23fea 100644 --- a/test/providers/plate_calculator_test.mocks.dart +++ b/test/providers/plate_calculator_test.mocks.dart @@ -1,5 +1,5 @@ // Mocks generated by Mockito 5.4.6 from annotations -// in wger/test/providers/plate_weights_test.dart. +// in wger/test/providers/plate_calculator_test.dart. // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes diff --git a/test/routine/gym_mode_screen_test.dart b/test/routine/gym_mode_screen_test.dart index f3c1c129..02c65cb9 100644 --- a/test/routine/gym_mode_screen_test.dart +++ b/test/routine/gym_mode_screen_test.dart @@ -22,6 +22,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:provider/provider.dart'; +import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; +import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; import 'package:wger/helpers/json.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; import 'package:wger/providers/base_provider.dart'; @@ -52,6 +54,8 @@ void main() { final testExercises = getTestExercises(); Widget renderGymMode({locale = 'en'}) { + SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty(); + return ChangeNotifierProvider( create: (context) => RoutinesProvider( mockBaseProvider, diff --git a/test/weight/weight_screen_test.mocks.dart b/test/weight/weight_screen_test.mocks.dart index dcdc9f48..23aafa61 100644 --- a/test/weight/weight_screen_test.mocks.dart +++ b/test/weight/weight_screen_test.mocks.dart @@ -339,16 +339,6 @@ class MockUserProvider extends _i1.Mock implements _i13.UserProvider { returnValueForMissingStub: null, ); - @override - void changeUnit({dynamic changeTo = 'kg'}) => super.noSuchMethod( - Invocation.method( - #changeUnit, - [], - {#changeTo: changeTo}, - ), - returnValueForMissingStub: null, - ); - @override void setThemeMode(_i14.ThemeMode? mode) => super.noSuchMethod( Invocation.method(