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 { ...@@ -1825,7 +1825,6 @@ class InheritedElement extends _ProxyElement {
/// the build phase. /// the build phase.
void dispatchDependenciesChanged() { void dispatchDependenciesChanged() {
for (Element dependent in _dependents) { for (Element dependent in _dependents) {
dependent.dependenciesChanged();
assert(() { assert(() {
// check that it really is our descendant // check that it really is our descendant
Element ancestor = dependent._parent; Element ancestor = dependent._parent;
...@@ -1835,6 +1834,7 @@ class InheritedElement extends _ProxyElement { ...@@ -1835,6 +1834,7 @@ class InheritedElement extends _ProxyElement {
}); });
// check that it really deepends on us // check that it really deepends on us
assert(dependent._dependencies.contains(this)); assert(dependent._dependencies.contains(this));
dependent.dependenciesChanged();
} }
} }
} }
......
...@@ -132,6 +132,14 @@ class _LayoutBuilderElement extends RenderObjectElement { ...@@ -132,6 +132,14 @@ class _LayoutBuilderElement extends RenderObjectElement {
renderObject.markNeedsLayout(); 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 @override
void unmount() { void unmount() {
renderObject.callback = null; renderObject.callback = null;
......
...@@ -116,4 +116,51 @@ void main() { ...@@ -116,4 +116,51 @@ void main() {
box = tester.renderObject(find.byKey(childKey)); box = tester.renderObject(find.byKey(childKey));
expect(box.size, equals(const Size(100.0, 200.0))); 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