-
-
Notifications
You must be signed in to change notification settings - Fork 263
Fix onboarding weight validation text and negative profile values #303
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
simonoppowa
merged 3 commits into
simonoppowa:develop
from
LarytheLord:fix/signup-weight-validation-288
Apr 18, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
lib/features/profile/presentation/utils/profile_picker_bounds.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import 'dart:math'; | ||
|
|
||
| const _heightRangeCm = 100.0; | ||
| const _heightRangeFt = 10.0; | ||
| const _weightRangeKg = 50.0; | ||
| const _weightRangeLbs = 100.0; | ||
| const _minHeight = 1.0; | ||
| const _minWeight = 1.0; | ||
|
|
||
| double minSelectableHeight(double userHeight, bool usesImperialUnits) { | ||
| final range = usesImperialUnits ? _heightRangeFt : _heightRangeCm; | ||
| return max(_minHeight, userHeight - range); | ||
| } | ||
|
|
||
| double maxSelectableHeight(double userHeight, bool usesImperialUnits) { | ||
| final range = usesImperialUnits ? _heightRangeFt : _heightRangeCm; | ||
| final clampedMin = minSelectableHeight(userHeight, usesImperialUnits); | ||
| final rawMax = userHeight + range; | ||
| return max(clampedMin + range, rawMax); | ||
| } | ||
|
|
||
| double clampHeightSelection(double selectedHeight, double minHeight) { | ||
| return max(minHeight, selectedHeight); | ||
| } | ||
|
|
||
| double minSelectableWeight(double userWeight, bool usesImperialUnits) { | ||
| final range = usesImperialUnits ? _weightRangeLbs : _weightRangeKg; | ||
| return max(_minWeight, userWeight - range); | ||
| } | ||
|
|
||
| double maxSelectableWeight(double userWeight, bool usesImperialUnits) { | ||
| final range = usesImperialUnits ? _weightRangeLbs : _weightRangeKg; | ||
| final minWeight = minSelectableWeight(userWeight, usesImperialUnits); | ||
| final candidateMaxWeight = userWeight + range; | ||
| return max(minWeight + range, candidateMaxWeight); | ||
| } | ||
|
|
||
| double clampWeightSelection(double selectedWeight, double minWeight) { | ||
| return max(minWeight, selectedWeight); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:opennutritracker/features/profile/presentation/utils/profile_picker_bounds.dart'; | ||
|
|
||
| void main() { | ||
| group('profile picker bounds', () { | ||
| test('metric height minimum is clamped to 1', () { | ||
| expect(minSelectableHeight(80, false), 1); | ||
| }); | ||
|
|
||
| test('imperial height minimum is clamped to 1', () { | ||
| expect(minSelectableHeight(5, true), 1); | ||
| }); | ||
|
|
||
| test('metric height maximum keeps expected range', () { | ||
| expect(maxSelectableHeight(170, false), 270); | ||
| }); | ||
|
|
||
| test('weight minimum is clamped to 1 for metric and imperial', () { | ||
| expect(minSelectableWeight(40, false), 1); | ||
| expect(minSelectableWeight(80, true), 1); | ||
| }); | ||
|
|
||
| test('weight maximum keeps expected range', () { | ||
| expect(maxSelectableWeight(75, false), 125); | ||
| expect(maxSelectableWeight(140, true), 240); | ||
| }); | ||
|
|
||
| test('extreme negative persisted values still produce a valid metric range', () { | ||
| expect( | ||
| maxSelectableHeight(-200, false) >= minSelectableHeight(-200, false), | ||
| isTrue, | ||
| ); | ||
| expect( | ||
| maxSelectableWeight(-200, false) >= minSelectableWeight(-200, false), | ||
| isTrue, | ||
| ); | ||
| }); | ||
|
|
||
| test('selected values are clamped to computed minimum', () { | ||
| expect(clampHeightSelection(0.5, 1), 1); | ||
| expect(clampWeightSelection(0.5, 1), 1); | ||
| expect(clampHeightSelection(180, 1), 180); | ||
| expect(clampWeightSelection(80, 1), 80); | ||
| }); | ||
| }); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.