Skip to content

Commit

Permalink
Fixed bug where number of reps were not shown with max weight in reco…
Browse files Browse the repository at this point in the history
…rds tab (#228)

* Fixed bug where number of reps were not shown with max weight in records tab

* Bump v0.5.3+23
  • Loading branch information
andreped authored Sep 4, 2024
1 parent bd3af40 commit e68f2f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
14 changes: 12 additions & 2 deletions lib/core/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,19 @@ class DatabaseHelper {
final db = await database;
final List<Map<String, dynamic>> maxWeights = await db.rawQuery(
'''
SELECT exercise, MAX(CAST(weight AS REAL)) as max_weight
SELECT exercise, weight, reps
FROM exercises
GROUP BY exercise
WHERE (exercise, CAST(weight AS REAL), reps) IN (
SELECT exercise, weight, MAX(reps)
FROM exercises
WHERE (exercise, CAST(weight AS REAL)) IN (
SELECT exercise, MAX(CAST(weight AS REAL))
FROM exercises
GROUP BY exercise
)
GROUP BY exercise, weight
)
ORDER BY exercise
''',
);

Expand Down
5 changes: 3 additions & 2 deletions lib/widgets/records.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class _RecordsTabState extends State<RecordsTab> {
itemBuilder: (context, index) {
final record = _maxWeights[index];
final exercise = record['exercise'] as String;
final weight = record['max_weight'];
final weight = record['weight'];
final reps = record['reps'];
final displayWeight = _convertWeight(
weight is String ? double.parse(weight) : weight);

Expand All @@ -119,7 +120,7 @@ class _RecordsTabState extends State<RecordsTab> {
ListTile(
title: Text(exercise),
trailing: Text(
'${displayWeight.toStringAsFixed(1)} ${widget.isKg ? 'kg' : 'lbs'}'),
'${displayWeight.toStringAsFixed(1)} ${widget.isKg ? 'kg' : 'lbs'} x $reps reps'),
),
if (index < _maxWeights.length - 1) Divider(),
],
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.5.2+23
version: 0.5.3+23

environment:
sdk: '>=3.4.3 <4.0.0'
Expand Down

0 comments on commit e68f2f9

Please sign in to comment.