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

This commit is contained in:
Ayush Bherwani 2020-09-15 06:32:05 +05:30 committed by GitHub
parent bcd0959ac3
commit 4e89ccfdee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -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
bool hitTestChildren(BoxHitTestResult result, { Offset position }) {
return child?.hitTest(result, position: position) ?? false;

View File

@ -93,6 +93,26 @@ void main() {
await tester.pump();
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 {
@ -133,7 +153,7 @@ class RenderBaselineDetector extends RenderBox {
double computeDistanceToActualBaseline(TextBaseline baseline) {
if (callback != null)
callback();
return 0.0;
return 20.0;
}
void dirty() {