Unverified Commit a1203429 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix flex methods for min and max column widths (#131724)

Fixes https://github.com/flutter/flutter/issues/131467

An error in the flex methods of min and max column width would produce different results based on the position of the widths that were provided:
`MaxColumnWidth(a, b) != MaxColumnWidth(b, a)`

This fixes that.
parent f9e4567f
......@@ -263,12 +263,11 @@ class MaxColumnWidth extends TableColumnWidth {
@override
double? flex(Iterable<RenderBox> cells) {
final double? aFlex = a.flex(cells);
if (aFlex == null) {
return b.flex(cells);
}
final double? bFlex = b.flex(cells);
if (bFlex == null) {
return null;
if (aFlex == null) {
return bFlex;
} else if (bFlex == null) {
return aFlex;
}
return math.max(aFlex, bFlex);
}
......@@ -316,12 +315,11 @@ class MinColumnWidth extends TableColumnWidth {
@override
double? flex(Iterable<RenderBox> cells) {
final double? aFlex = a.flex(cells);
if (aFlex == null) {
return b.flex(cells);
}
final double? bFlex = b.flex(cells);
if (bFlex == null) {
return null;
if (aFlex == null) {
return bFlex;
} else if (bFlex == null) {
return aFlex;
}
return math.min(aFlex, bFlex);
}
......
......@@ -277,4 +277,37 @@ void main() {
);
});
test('MaxColumnWidth.flex returns the correct result', () {
MaxColumnWidth columnWidth = const MaxColumnWidth(
FixedColumnWidth(100), // returns null from .flex
FlexColumnWidth(), // returns 1 from .flex
);
final double? flexValue = columnWidth.flex(<RenderBox>[]);
expect(flexValue, 1.0);
// Swap a and b, check for same result.
columnWidth = const MaxColumnWidth(
FlexColumnWidth(), // returns 1 from .flex
FixedColumnWidth(100), // returns null from .flex
);
// Same result.
expect(columnWidth.flex(<RenderBox>[]), flexValue);
});
test('MinColumnWidth.flex returns the correct result', () {
MinColumnWidth columnWidth = const MinColumnWidth(
FixedColumnWidth(100), // returns null from .flex
FlexColumnWidth(), // returns 1 from .flex
);
final double? flexValue = columnWidth.flex(<RenderBox>[]);
expect(flexValue, 1.0);
// Swap a and b, check for same result.
columnWidth = const MinColumnWidth(
FlexColumnWidth(), // returns 1 from .flex
FixedColumnWidth(100), // returns null from .flex
);
// Same result.
expect(columnWidth.flex(<RenderBox>[]), flexValue);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment