Do not add spacing to the first child's width in RenderWrap line wrapping (#15272)

The first child fits on the line if the line can accomodate its width.
After the first child the line needs room for the child's width plus spacing.
This commit is contained in:
Jason Simmons
2018-03-08 15:01:37 -08:00
committed by GitHub
parent d996ab921c
commit 6f5bcb97a4
2 changed files with 16 additions and 2 deletions

View File

@@ -608,8 +608,7 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr
child.layout(childConstraints, parentUsesSize: true);
final double childMainAxisExtent = _getMainAxisExtent(child);
final double childCrossAxisExtent = _getCrossAxisExtent(child);
if (runMainAxisExtent + childMainAxisExtent + spacing > mainAxisLimit) {
assert(childCount > 0);
if (childCount > 0 && runMainAxisExtent + spacing + childMainAxisExtent > mainAxisLimit) {
mainAxisExtent = math.max(mainAxisExtent, runMainAxisExtent);
crossAxisExtent += runCrossAxisExtent;
if (runMetrics.isNotEmpty)

View File

@@ -851,4 +851,19 @@ void main() {
const Offset(0.0, 20.0)
]);
});
testWidgets('Object exactly matches container width', (WidgetTester tester) async {
await tester.pumpWidget(new Wrap(
direction: Axis.horizontal,
textDirection: TextDirection.ltr,
spacing: 10.0,
runSpacing: 10.0,
children: <Widget>[
const SizedBox(width: 800.0, height: 0.0),
],
));
expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
verify(tester, <Offset>[const Offset(0.0, 0.0)]);
});
}