Unverified Commit 4e89ccfd authored by Ayush Bherwani's avatar Ayush Bherwani Committed by GitHub

[LayoutBuilder] Implements baseline logic to pass baseline to child (#65000)

parent bcd0959a
...@@ -361,6 +361,13 @@ class _RenderLayoutBuilder extends RenderBox with RenderObjectWithChildMixin<Ren ...@@ -361,6 +361,13 @@ class _RenderLayoutBuilder extends RenderBox with RenderObjectWithChildMixin<Ren
} }
} }
@override
double computeDistanceToActualBaseline(TextBaseline baseline) {
if (child != null)
return child.getDistanceToActualBaseline(baseline);
return super.computeDistanceToActualBaseline(baseline);
}
@override @override
bool hitTestChildren(BoxHitTestResult result, { Offset position }) { bool hitTestChildren(BoxHitTestResult result, { Offset position }) {
return child?.hitTest(result, position: position) ?? false; return child?.hitTest(result, position: position) ?? false;
......
...@@ -93,6 +93,26 @@ void main() { ...@@ -93,6 +93,26 @@ void main() {
await tester.pump(); await tester.pump();
expect(calls, 2); expect(calls, 2);
}); });
testWidgets('LayoutBuilder returns child\'s baseline', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Baseline(
baseline: 180.0,
baselineType: TextBaseline.alphabetic,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return BaselineDetector(() {});
},
),
),
),
),
);
expect(tester.getRect(find.byType(BaselineDetector)).top, 160.0);
});
} }
class BaselineDetector extends LeafRenderObjectWidget { class BaselineDetector extends LeafRenderObjectWidget {
...@@ -133,7 +153,7 @@ class RenderBaselineDetector extends RenderBox { ...@@ -133,7 +153,7 @@ class RenderBaselineDetector extends RenderBox {
double computeDistanceToActualBaseline(TextBaseline baseline) { double computeDistanceToActualBaseline(TextBaseline baseline) {
if (callback != null) if (callback != null)
callback(); callback();
return 0.0; return 20.0;
} }
void dirty() { void dirty() {
......
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