Skip to content

Conversation

@champeauxr
Copy link
Contributor

@champeauxr champeauxr commented Apr 3, 2019

This PR is to fix issue #30437

RenderTable._computeColumnWidths() had a logic error that caused flex columns to be collapsed to their minimum widths in certain situations dependent on the layout width constraint and the number of flex columns.

The problem was in a loop at the end of RenderTable._computeColumnWidths. After the flex columns are grown to fill the width constraint and if the table size is now greater than the constraint, this loop is supposed to evenly remove a portion of the deficit from each flex column to bring the table width into the constraint. Instead it removes all of flex space in each column and in the example code reduces every column to zero width.

The error is in the last if/else statement:

              if (availableDelta <= delta) {
                // shrank to minimum
                deficit -= widths[x] - minWidths[x];
                widths[x] = minWidths[x];
              } else {
                deficit -= availableDelta;
                widths[x] -= availableDelta;
                newAvailableColumns += 1;
              }

The delta variable was calculated to be the even portion of the deficit that is to be subtracted from each column:

final double delta = deficit / availableColumns;

The if/else statement is supposed to remove the availableDelta from a column width if availableDelta is less than delta, otherwise it should be subtracting delta from the columnWidth.

Instead, if availableDelta is greater than delta, it's removing all of availableDelta from the column width, which collapses it to its minimum width. The else statements should have been subtracting delta, not availableDelta.

Tests

A test was added to verify that a table with a constrained width evenly distributes its width between its columns. Prior to the fix, this test would fail and would result in zero width columns.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read [Handling breaking changes]). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

r

RenderTable._computeColumnWidths() had a logic error that caused flex columns to be collapsed to their minimum widths in certain situations dependent on the layout width constraint and the number of flex columns.
@goderbauer
Copy link
Member

Thanks for the contribution. In order for us to review and accept the PR you will have to add a test to ensure that we never break this again. Can you please add one?

@goderbauer goderbauer added the framework flutter/packages/flutter repository. See also f: labels. label Apr 4, 2019
@Piinks Piinks added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 4, 2019
@champeauxr
Copy link
Contributor Author

champeauxr commented Apr 5, 2019

Added a unit test that tests that flex columns evenly receive the available flex space when the table width is constrained. This test would fail prior to the fix in this PR.

@goderbauer goderbauer removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 8, 2019
test('Table control test: constrained flex columns', () {
final RenderTable table = RenderTable(textDirection: TextDirection.ltr);
final List<RenderBox> children =
List<RenderBox>.generate(6, (_) => RenderPositionedBox());
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just be one line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since you approved the PR, I'm not sure if you are actually wanting me to change this or not. But I can.
However, if I change the children assignment statement into a single line, it will exceed 80 characters (95 total) and dartfmt splits into two lines as I had it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be best if you could fix this. I realize it goes over 80 characters, but our style guide prefers not wrapping this vs going over 80 chars. I approved it because overall the functionality is good, so once this is fixed it should be good to land.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM modulo minor style nit

@dnfield dnfield merged commit a5dd074 into flutter:master Apr 11, 2019
jiisd added a commit to jiisd/flutter that referenced this pull request Apr 12, 2019
* master: (209 commits)
  Allow mouse hover to only respond to some mouse events but not all. (flutter#30886)
  Fix issue 23527: Exception: RenderViewport exceeded its maximum number of layout cycles (flutter#30809)
  Keep hover annotation layers in sync with the mouse detector. (flutter#30829)
  Use identical instead of '==' in a constant expression. (flutter#30921)
  Add toggle for debugProfileWidgetBuilds (flutter#30867)
  Revert "Manual engine roll with disabled service authentication codes (flutter#30919)" (flutter#30930)
  Manual engine roll with disabled service authentication codes (flutter#30919)
  Baseline Aligned Row (flutter#30746)
  [Material] Fix showDialog crasher caused by old contexts (flutter#30754)
  Let `sliver.dart` `_createErrorWidget` work with other Widgets (flutter#30880)
  Add more dialog doc cross-reference (flutter#30887)
  Allow downloading of desktop embedding artifacts (flutter#30648)
  CupertinoDatePicker initialDateTime accounts for minuteInterval  (flutter#30862)
  add golden tests for CupertinoDatePicker (flutter#30828)
  Simplify toImage future handling (flutter#30876)
  Fixed Table flex column layout error flutter#30437 (flutter#30470)
  Fix iTunes Transporter quirk (flutter#30883)
  Bump Android build tools to 28.0.3 in Dockerfile (flutter#30832)
  Update the upload key which seems to have trouble for some reason (flutter#30871)
  Check for invalid elevations (flutter#30215)
  ...
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants