Skip to content

Plate calculator #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dart.lineLength": 100,
"diffEditor.ignoreTrimWhitespace": true,
"diffEditor.ignoreTrimWhitespace": true
}
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '14.0'
platform :ios, '17.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
28 changes: 14 additions & 14 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ PODS:
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- sqlite3 (3.49.1):
- sqlite3/common (= 3.49.1)
- sqlite3/common (3.49.1)
- sqlite3/dbstatvtab (3.49.1):
- sqlite3 (3.49.2):
- sqlite3/common (= 3.49.2)
- sqlite3/common (3.49.2)
- sqlite3/dbstatvtab (3.49.2):
- sqlite3/common
- sqlite3/fts5 (3.49.1):
- sqlite3/fts5 (3.49.2):
- sqlite3/common
- sqlite3/math (3.49.1):
- sqlite3/math (3.49.2):
- sqlite3/common
- sqlite3/perf-threadsafe (3.49.1):
- sqlite3/perf-threadsafe (3.49.2):
- sqlite3/common
- sqlite3/rtree (3.49.1):
- sqlite3/rtree (3.49.2):
- sqlite3/common
- sqlite3_flutter_libs (0.0.1):
- Flutter
- FlutterMacOS
- sqlite3 (~> 3.49.1)
- sqlite3 (~> 3.49.2)
- sqlite3/dbstatvtab
- sqlite3/fts5
- sqlite3/math
Expand Down Expand Up @@ -101,22 +101,22 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/video_player_avfoundation/darwin"

SPEC CHECKSUMS:
camera_avfoundation: 04b44aeb14070126c6529e5ab82cc7c9fca107cf
camera_avfoundation: be3be85408cd4126f250386828e9b1dfa40ab436
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_keyboard_visibility: 4625131e43015dbbe759d9b20daaf77e0e3f6619
flutter_zxing: e741c4f3335db8910e5c396c4291cdfb320859dc
flutter_zxing: e8bcc43bd3056c70c271b732ed94e7a16fd62f93
image_picker_ios: 7fe1ff8e34c1790d6fff70a32484959f563a928a
integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e
package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
pointer_interceptor_ios: ec847ef8b0915778bed2b2cef636f4d177fa8eed
rive_common: dd421daaf9ae69f0125aa761dd96abd278399952
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
sqlite3: fc1400008a9b3525f5914ed715a5d1af0b8f4983
sqlite3_flutter_libs: f6acaa2172e6bb3e2e70c771661905080e8ebcf2
sqlite3: 3c950dc86011117c307eb0b28c4a7bb449dce9f1
sqlite3_flutter_libs: 74334e3ef2dbdb7d37e50859bb45da43935779c4
url_launcher_ios: 694010445543906933d732453a59da0a173ae33d
video_player_avfoundation: 2cef49524dd1f16c5300b9cd6efd9611ce03639b

PODFILE CHECKSUM: 775997f741c536251164e3eacf6e34abf2eb7a17
PODFILE CHECKSUM: 5a367937f10bf0c459576e5e472a1159ee029c13

COCOAPODS: 1.16.2
2 changes: 2 additions & 0 deletions lib/helpers/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ const LIBERAPAY_URL = 'https://liberapay.com/wger';
/// the milliseconds themselves can cause the application to crash since it runs
/// out of memory...
const double CHART_MILLISECOND_FACTOR = 100000.0;

enum WeightUnitEnum { kg, lb }
15 changes: 10 additions & 5 deletions lib/helpers/gym_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,35 @@

/// Calculates the number of plates needed to reach a specific weight
List<num> plateCalculator(num totalWeight, num barWeight, List<num> plates) {
final List<num> ans = [];
final List<num> result = [];
final sortedPlates = List.of(plates)..sort();

// Weight is less than the bar
if (totalWeight < barWeight) {
return [];
}

if (sortedPlates.isEmpty) {
return [];
}

// Remove the bar and divide by two to get weight on each side
totalWeight = (totalWeight - barWeight) / 2;

// Weight can't be divided with the smallest plate
if (totalWeight % plates.first > 0) {
if (totalWeight % sortedPlates.first > 0) {
return [];
}

// Iterate through the plates, beginning with the biggest ones
for (final plate in plates.reversed) {
for (final plate in sortedPlates.reversed) {
while (totalWeight >= plate) {
totalWeight -= plate;
ans.add(plate);
result.add(plate);
}
}

return ans;
return result;
}

/// Groups a list of plates as calculated by [plateCalculator]
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"@passwordTooShort": {
"description": "Error message when the user a password that is too short"
},
"selectAvailablePlates": "Select available plates",
"barWeight": "Bar weight",
"useColors": "Use colors",
"password": "Password",
"@password": {},
"confirmPassword": "Confirm password",
Expand Down
30 changes: 17 additions & 13 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import 'package:wger/providers/routines.dart';
import 'package:wger/providers/user.dart';
import 'package:wger/screens/add_exercise_screen.dart';
import 'package:wger/screens/auth_screen.dart';
import 'package:wger/screens/configure_plates_screen.dart';
import 'package:wger/screens/dashboard.dart';
import 'package:wger/screens/exercise_screen.dart';
import 'package:wger/screens/exercises_screen.dart';
Expand Down Expand Up @@ -90,19 +91,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);
};
// 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) {
Expand All @@ -114,6 +116,7 @@ void main() async {
showHttpExceptionErrorDialog(error);
} else {
showGeneralErrorDialog(error, stack);
// throw error;
}

// Return true to indicate that the error has been handled.
Expand Down Expand Up @@ -242,6 +245,7 @@ class MainApp extends StatelessWidget {
AddExerciseScreen.routeName: (ctx) => const AddExerciseScreen(),
AboutPage.routeName: (ctx) => const AboutPage(),
SettingsPage.routeName: (ctx) => const SettingsPage(),
ConfigurePlatesScreen.routeName: (ctx) => const ConfigurePlatesScreen(),
},
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
Expand Down
Loading