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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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); child.layout(childConstraints, parentUsesSize: true);
final double childMainAxisExtent = _getMainAxisExtent(child); final double childMainAxisExtent = _getMainAxisExtent(child);
final double childCrossAxisExtent = _getCrossAxisExtent(child); final double childCrossAxisExtent = _getCrossAxisExtent(child);
if (runMainAxisExtent + childMainAxisExtent + spacing > mainAxisLimit) { if (childCount > 0 && runMainAxisExtent + spacing + childMainAxisExtent > mainAxisLimit) {
assert(childCount > 0);
mainAxisExtent = math.max(mainAxisExtent, runMainAxisExtent); mainAxisExtent = math.max(mainAxisExtent, runMainAxisExtent);
crossAxisExtent += runCrossAxisExtent; crossAxisExtent += runCrossAxisExtent;
if (runMetrics.isNotEmpty) if (runMetrics.isNotEmpty)

View File

@ -851,4 +851,19 @@ void main() {
const Offset(0.0, 20.0) 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)]);
});
} }