fix: scale customWidths/customHeights proportionally when they exceed screen bounds (#94)#105
Open
Vasusn wants to merge 1 commit into
Open
fix: scale customWidths/customHeights proportionally when they exceed screen bounds (#94)#105Vasusn wants to merge 1 commit into
Vasusn wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds proportional down-scaling for customWidths / customHeights when their totals exceed available screen bounds, aiming to avoid Flex overflow behavior that can negate per-switch sizing.
Changes:
- Introduce
_scaleIfNeededinUtilsand apply it incalculateWidth/calculateHeightwhen custom dimensions are provided. - Add a widget test intended to cover the “custom widths exceed screen width” scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/src/utils.dart | Applies proportional scaling for custom widths/heights via a new _scaleIfNeeded helper. |
| test/toggle_switch_test.dart | Adds a regression test case around oversized customWidths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… screen bounds (PramodJoshi#94) ## Problem `customWidths` (and `customHeights`) were returned as-is without any overflow guard. When the total of all custom widths exceeded the screen width (especially with `minWidth: double.maxFinite`), Flutter's `Flexible` layout ignored individual width values and distributed space equally, making custom widths appear to have no effect. ## Solution Added a `_scaleIfNeeded` helper in `Utils` that proportionally scales a custom dimension down when the total of all values exceeds the available screen space. Relative ratios between switches are preserved. ## Changes - lib/src/utils.dart: `calculateWidth` and `calculateHeight` now apply proportional scaling to `customWidths`/`customHeights` when they overflow the screen - test/toggle_switch_test.dart: new test verifying overflow scaling renders without exceptions and shows all labels Fixes PramodJoshi#94
85c44e6 to
a5ddeba
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
customWidths(andcustomHeights) were returned as-is without any overflow guard. When the total of all custom widths exceeded the screen width (especially withminWidth: double.maxFinite), Flutter'sFlexiblelayout ignored individual width values and distributed space equally, making custom widths appear to have no effect.Solution
Added a
_scaleIfNeededhelper inUtilsthat proportionally scales a custom dimension down when the total of all values exceeds the available screen space. Relative ratios between switches are preserved.Changes
calculateWidthandcalculateHeightnow apply proportional scaling tocustomWidths/customHeightswhen they overflow the screenFixes #94