Commit 3b3db78f authored by Ian Hickson's avatar Ian Hickson

Teach LayoutBuilder about Inherited widgets. (#4140)

parent 390c7ce2
......@@ -1825,7 +1825,6 @@ class InheritedElement extends _ProxyElement {
/// the build phase.
void dispatchDependenciesChanged() {
for (Element dependent in _dependents) {
dependent.dependenciesChanged();
assert(() {
// check that it really is our descendant
Element ancestor = dependent._parent;
......@@ -1835,6 +1834,7 @@ class InheritedElement extends _ProxyElement {
});
// check that it really deepends on us
assert(dependent._dependencies.contains(this));
dependent.dependenciesChanged();
}
}
}
......
......@@ -119,7 +119,7 @@ class _LayoutBuilderElement extends RenderObjectElement {
@override
void mount(Element parent, dynamic newSlot) {
super.mount(parent, newSlot); // Creates the renderObject.
super.mount(parent, newSlot); // Creates the renderObject.
renderObject.callback = _layout; // The _child will be built during layout.
}
......@@ -132,6 +132,14 @@ class _LayoutBuilderElement extends RenderObjectElement {
renderObject.markNeedsLayout();
}
@override
void performRebuild() {
// This gets called if markNeedsBuild() is called on us.
// That might happen if, e.g., our builder uses Inherited widgets.
renderObject.markNeedsLayout();
super.performRebuild(); // calls widget.updateRenderObject
}
@override
void unmount() {
renderObject.callback = null;
......
......@@ -116,4 +116,51 @@ void main() {
box = tester.renderObject(find.byKey(childKey));
expect(box.size, equals(const Size(100.0, 200.0)));
});
testWidgets('LayoutBuilder and Inherited -- do not rebuild when not using inherited', (WidgetTester tester) async {
int built = 0;
Widget target = new LayoutBuilder(
builder: (BuildContext context, Size size) {
built += 1;
return new Container();
}
);
expect(built, 0);
await tester.pumpWidget(new MediaQuery(
data: new MediaQueryData(size: const Size(400.0, 300.0)),
child: target
));
expect(built, 1);
await tester.pumpWidget(new MediaQuery(
data: new MediaQueryData(size: const Size(300.0, 400.0)),
child: target
));
expect(built, 1);
});
testWidgets('LayoutBuilder and Inherited -- do rebuild when using inherited', (WidgetTester tester) async {
int built = 0;
Widget target = new LayoutBuilder(
builder: (BuildContext context, Size size) {
built += 1;
MediaQuery.of(context);
return new Container();
}
);
expect(built, 0);
await tester.pumpWidget(new MediaQuery(
data: new MediaQueryData(size: const Size(400.0, 300.0)),
child: target
));
expect(built, 1);
await tester.pumpWidget(new MediaQuery(
data: new MediaQueryData(size: const Size(300.0, 400.0)),
child: target
));
expect(built, 2);
});
}
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