Skip to content

Commit

Permalink
Fix overflow bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pingbird committed Jun 16, 2022
1 parent f7d1ce9 commit 70299fc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [2.0.6+1]
* Added `BoxyDelegate.renderSize`
* Fixed bugs in `SliverContainer`
* Fixed slot bug in `SliverContainer`
* Fixed overflow bug in `BoxyFlex`

## [2.0.6]
* Added `BoxyLayerContext.imageFilter`
Expand Down
30 changes: 19 additions & 11 deletions lib/src/boxy_flex.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:math' as math;
import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -1107,6 +1108,9 @@ class RenderBoxyFlex extends RenderBox
required ChildLayouter layoutChild,
}) {
int totalFlex = 0;
final double minMainSize = _direction == Axis.horizontal
? constraints.minWidth
: constraints.minHeight;
final double maxMainSize = _direction == Axis.horizontal
? constraints.maxWidth
: constraints.maxHeight;
Expand Down Expand Up @@ -1275,14 +1279,15 @@ class RenderBoxyFlex extends RenderBox
math.max(0.0, (canFlex ? maxMainSize : 0.0) - allocatedSize);
final mainSize = (freeSpace / totalFlex) * _getFlex(dominantChild!);
final size = layoutChild(
dominantChild,
BoxConstraintsAxisUtil.create(
_direction,
minCross: 0,
maxCross: maxCrossSize,
minMain: _getFit(dominantChild) == FlexFit.tight ? mainSize : 0.0,
maxMain: mainSize,
));
dominantChild,
BoxConstraintsAxisUtil.create(
_direction,
minCross: 0,
maxCross: maxCrossSize,
minMain: _getFit(dominantChild) == FlexFit.tight ? mainSize : 0.0,
maxMain: mainSize,
),
);
maxCrossSize = crossSize = size.crossAxisSize(_direction);
} else if (hasInflexible) {
// Lay out inflexible children to calculate the allocatedSize, giving
Expand Down Expand Up @@ -1398,9 +1403,12 @@ class RenderBoxyFlex extends RenderBox
}

return _LayoutSizes(
mainSize: canFlex && mainAxisSize == MainAxisSize.max
? maxMainSize
: allocatedSize,
mainSize: max(
minMainSize,
canFlex && mainAxisSize == MainAxisSize.max
? maxMainSize
: min(maxMainSize, allocatedSize),
),
crossSize: crossSize,
allocatedSize: allocatedSize,
needsBaseline: needsBaseline,
Expand Down
30 changes: 29 additions & 1 deletion test/flex_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ void main() {
key: GlobalObjectKey(#second),
child: RotatedBox(
child: Text(
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
),
quarterTurns: 1,
),
),
Expand Down Expand Up @@ -422,4 +423,31 @@ void main() {
}
}
});

testWidgets('handles overflow properly', (tester) async {
await tester.pumpWidget(
TestFrame(
child: SizedBox(
width: 200,
child: BoxyRow(
mainAxisSize: MainAxisSize.min,
children: const [
BoxyFlexible.align(
child: SizedBox(
width: 400,
height: 400,
),
crossAxisAlignment: CrossAxisAlignment.start,
),
],
),
),
constraints: BoxConstraints.loose(const Size(300, 300)),
),
);
expect(
tester.takeException().toString(),
contains('A RenderBoxyFlex overflowed by 200 pixels on the right.'),
);
});
}

0 comments on commit 70299fc

Please sign in to comment.