Commit 827af771 authored by Hans Muller's avatar Hans Muller

Merge pull request #1922 from HansMuller/justifycontent_collapse

Adds FlexJustifyContent.collapse
parents 766eda6b d88cad16
......@@ -46,6 +46,8 @@ enum FlexJustifyContent {
spaceBetween,
/// Place the free space evenly between the children as well as before and after the first and last child
spaceAround,
/// Do not expand to fill the free space. None of the children may specify a flex factor.
collapse,
}
/// How the children should be placed along the cross axis in a flex layout
......@@ -337,7 +339,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
int totalChildren = 0;
assert(constraints != null);
final double mainSize = (_direction == FlexDirection.horizontal) ? constraints.constrainWidth() : constraints.constrainHeight();
final bool canFlex = mainSize < double.INFINITY;
final bool canFlex = mainSize < double.INFINITY && justifyContent != FlexJustifyContent.collapse;
double crossSize = 0.0; // This is determined as we lay out the children
double freeSpace = canFlex ? mainSize : 0.0;
RenderBox child = firstChild;
......@@ -478,6 +480,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
}
switch (_justifyContent) {
case FlexJustifyContent.start:
case FlexJustifyContent.collapse:
leadingSpace = 0.0;
betweenSpace = 0.0;
break;
......
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:test/test.dart';
......@@ -42,4 +43,66 @@ void main() {
expect(didReceiveTap, isTrue);
});
});
test('Row, Column and FlexJustifyContent.collapse', () {
final Key flexKey = new Key('flexKey');
// Row without justifyContent: FlexJustifyContent.collapse
testWidgets((WidgetTester tester) {
tester.pumpWidget(new Center(
child: new Row([
new Container(width: 10.0, height: 100.0),
new Container(width: 30.0, height: 100.0)
],
key: flexKey
)
));
RenderBox renderBox = tester.findElementByKey(flexKey).renderObject;
expect(renderBox.size.width, equals(800.0));
expect(renderBox.size.height, equals(100.0));
// Row with justifyContent: FlexJustifyContent.collapse
tester.pumpWidget(new Center(
child: new Row([
new Container(width: 10.0, height: 100.0),
new Container(width: 30.0, height: 100.0)
],
key: flexKey,
justifyContent: FlexJustifyContent.collapse
)
));
renderBox = tester.findElementByKey(flexKey).renderObject;
expect(renderBox.size.width, equals(40.0));
expect(renderBox.size.height, equals(100.0));
});
// Column without justifyContent: FlexJustifyContent.collapse
testWidgets((WidgetTester tester) {
tester.pumpWidget(new Center(
child: new Column([
new Container(width: 100.0, height: 100.0),
new Container(width: 100.0, height: 150.0)
],
key: flexKey
)
));
RenderBox renderBox = tester.findElementByKey(flexKey).renderObject;
expect(renderBox.size.width, equals(100.0));
expect(renderBox.size.height, equals(600.0));
// Column with justifyContent: FlexJustifyContent.collapse
tester.pumpWidget(new Center(
child: new Column([
new Container(width: 100.0, height: 100.0),
new Container(width: 100.0, height: 150.0)
],
key: flexKey,
justifyContent: FlexJustifyContent.collapse
)
));
renderBox = tester.findElementByKey(flexKey).renderObject;
expect(renderBox.size.width, equals(100.0));
expect(renderBox.size.height, equals(250.0));
});
});
}
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