Commit fc2e31b8 authored by Adam Barth's avatar Adam Barth

You should be able to nest Scaffolds

Prior to this patch, MultiChildLayoutDelegate couldn't be re-entered because it
cleared _idToChild when unwinding its stack. Now we restore the previous value
of _idToChild when we unwind.
parent 56a81089
...@@ -10,7 +10,7 @@ class MultiChildLayoutParentData extends ContainerBoxParentDataMixin<RenderBox> ...@@ -10,7 +10,7 @@ class MultiChildLayoutParentData extends ContainerBoxParentDataMixin<RenderBox>
} }
abstract class MultiChildLayoutDelegate { abstract class MultiChildLayoutDelegate {
final Map<Object, RenderBox> _idToChild = new Map<Object, RenderBox>(); Map<Object, RenderBox> _idToChild;
/// Returns the size of this object given the incomming constraints. /// Returns the size of this object given the incomming constraints.
/// The size cannot reflect the instrinsic sizes of the children. /// The size cannot reflect the instrinsic sizes of the children.
...@@ -39,6 +39,9 @@ abstract class MultiChildLayoutDelegate { ...@@ -39,6 +39,9 @@ abstract class MultiChildLayoutDelegate {
} }
void _callPerformLayout(Size size, BoxConstraints constraints, RenderBox firstChild) { void _callPerformLayout(Size size, BoxConstraints constraints, RenderBox firstChild) {
final Map<Object, RenderBox> previousIdToChild = _idToChild;
try {
_idToChild = new Map<Object, RenderBox>();
RenderBox child = firstChild; RenderBox child = firstChild;
while (child != null) { while (child != null) {
final MultiChildLayoutParentData childParentData = child.parentData; final MultiChildLayoutParentData childParentData = child.parentData;
...@@ -47,7 +50,9 @@ abstract class MultiChildLayoutDelegate { ...@@ -47,7 +50,9 @@ abstract class MultiChildLayoutDelegate {
child = childParentData.nextSibling; child = childParentData.nextSibling;
} }
performLayout(size, constraints); performLayout(size, constraints);
_idToChild.clear(); } finally {
_idToChild = previousIdToChild;
}
} }
/// Layout and position all children given this widget's size and the specified /// Layout and position all children given this widget's size and the specified
......
...@@ -19,11 +19,13 @@ class TestMultiChildLayoutDelegate extends MultiChildLayoutDelegate { ...@@ -19,11 +19,13 @@ class TestMultiChildLayoutDelegate extends MultiChildLayoutDelegate {
bool performLayoutIsChild; bool performLayoutIsChild;
void performLayout(Size size, BoxConstraints constraints) { void performLayout(Size size, BoxConstraints constraints) {
expect(() {
performLayoutSize = size; performLayoutSize = size;
performLayoutConstraints = constraints; performLayoutConstraints = constraints;
performLayoutSize0 = layoutChild(0, constraints); performLayoutSize0 = layoutChild(0, constraints);
performLayoutSize1 = layoutChild(1, constraints); performLayoutSize1 = layoutChild(1, constraints);
performLayoutIsChild = isChild('fred'); performLayoutIsChild = isChild('fred');
}, returnsNormally);
} }
} }
...@@ -34,7 +36,7 @@ void main() { ...@@ -34,7 +36,7 @@ void main() {
tester.pumpWidget(new Center( tester.pumpWidget(new Center(
child: new CustomMultiChildLayout([ child: new CustomMultiChildLayout([
new LayoutId(id: 0, child: new Container(width: 150.0, height: 100.0)), new LayoutId(id: 0, child: new Container(width: 150.0, height: 100.0)),
new LayoutId(id: 1, child: new Container(width: 100.0, height: 200.0)) new LayoutId(id: 1, child: new Container(width: 100.0, height: 200.0)),
], ],
delegate: delegate delegate: delegate
) )
...@@ -58,4 +60,23 @@ void main() { ...@@ -58,4 +60,23 @@ void main() {
expect(delegate.performLayoutIsChild, false); expect(delegate.performLayoutIsChild, false);
}); });
}); });
test('Nested CustomMultiChildLayouts', () {
testWidgets((WidgetTester tester) {
TestMultiChildLayoutDelegate delegate = new TestMultiChildLayoutDelegate();
tester.pumpWidget(new Center(
child: new CustomMultiChildLayout([
new LayoutId(
id: 0,
child: new CustomMultiChildLayout([
new LayoutId(id: 0, child: new Container(width: 150.0, height: 100.0)),
new LayoutId(id: 1, child: new Container(width: 100.0, height: 200.0)),
], delegate: delegate)
),
new LayoutId(id: 1, child: new Container(width: 100.0, height: 200.0)),
], delegate: delegate)
));
});
});
} }
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