diff --git a/packages/flutter/lib/src/rendering/table.dart b/packages/flutter/lib/src/rendering/table.dart index 2208664399fc..2cc86091ce05 100644 --- a/packages/flutter/lib/src/rendering/table.dart +++ b/packages/flutter/lib/src/rendering/table.dart @@ -263,12 +263,11 @@ class MaxColumnWidth extends TableColumnWidth { @override double? flex(Iterable 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 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); } diff --git a/packages/flutter/test/rendering/table_test.dart b/packages/flutter/test/rendering/table_test.dart index 12ff18b0352a..78386e7c2608 100644 --- a/packages/flutter/test/rendering/table_test.dart +++ b/packages/flutter/test/rendering/table_test.dart @@ -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([]); + 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([]), 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([]); + 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([]), flexValue); + }); }