Skip to content

fix: scale customWidths/customHeights proportionally when they exceed screen bounds (#94)#105

Open
Vasusn wants to merge 1 commit into
PramodJoshi:masterfrom
Vasusn:fix/issue-94-custom-widths
Open

fix: scale customWidths/customHeights proportionally when they exceed screen bounds (#94)#105
Vasusn wants to merge 1 commit into
PramodJoshi:masterfrom
Vasusn:fix/issue-94-custom-widths

Conversation

@Vasusn
Copy link
Copy Markdown

@Vasusn Vasusn commented Apr 26, 2026

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 #94

Copilot AI review requested due to automatic review settings April 26, 2026 10:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _scaleIfNeeded in Utils and apply it in calculateWidth / calculateHeight when 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.

Comment thread lib/src/utils.dart Outdated
Comment thread lib/src/utils.dart Outdated
Comment thread test/toggle_switch_test.dart
Comment thread test/toggle_switch_test.dart Outdated
… 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
@Vasusn Vasusn force-pushed the fix/issue-94-custom-widths branch from 85c44e6 to a5ddeba Compare April 26, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom Widths not being honored

2 participants