Skip to content

Commit eca833b

Browse files
committed
Use our own HtmlLayoutBuilder to avoid test failures
1 parent 342df89 commit eca833b

File tree

6 files changed

+95
-5
lines changed

6 files changed

+95
-5
lines changed

demo_app/devtools_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: This file stores settings for Dart & Flutter DevTools.
2+
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
3+
extensions:

packages/core/lib/src/core_helpers.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export 'widgets/css_sizing.dart';
1515
export 'widgets/horizontal_margin.dart';
1616
export 'widgets/html_details.dart';
1717
export 'widgets/html_flex.dart';
18+
export 'widgets/html_layout_builder.dart';
1819
export 'widgets/html_list_item.dart';
1920
export 'widgets/html_list_marker.dart';
2021
export 'widgets/html_ruby.dart';

packages/core/lib/src/core_widget_factory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {
233233
TextBaseline textBaseline = TextBaseline.alphabetic,
234234
TextDirection textDirection = TextDirection.ltr,
235235
}) {
236-
return LayoutBuilder(
236+
return HtmlLayoutBuilder(
237237
builder: (_, bc) {
238238
Widget built = HtmlFlex(
239239
crossAxisAlignment: crossAxisAlignment,

packages/core/lib/src/internal/ops/tag_table.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class TagTable {
8383
? tryParseCssLength(borderSpacingExpression)
8484
: null;
8585

86-
final layoutBuilder = LayoutBuilder(
86+
final layoutBuilder = HtmlLayoutBuilder(
8787
builder: (context, bc) {
8888
final resolved = tableTree.inheritanceResolvers.resolve(context);
8989
Widget built = ValignBaselineContainer(
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import 'package:flutter/rendering.dart';
2+
import 'package:flutter/widgets.dart';
3+
4+
/// Builds a widget tree that can depend on the parent widget's size.
5+
///
6+
/// The difference from [LayoutBuilder] is that this widget does not
7+
/// perform any assertions during the build phase.
8+
class HtmlLayoutBuilder extends ConstrainedLayoutBuilder<BoxConstraints> {
9+
/// Creates a widget that defers its building until layout.
10+
const HtmlLayoutBuilder({super.key, required super.builder});
11+
12+
@override
13+
RenderAbstractLayoutBuilderMixin<BoxConstraints, RenderBox>
14+
createRenderObject(
15+
BuildContext context,
16+
) =>
17+
_RenderLayoutBuilder();
18+
}
19+
20+
class _RenderLayoutBuilder extends RenderBox
21+
with
22+
RenderObjectWithChildMixin<RenderBox>,
23+
RenderObjectWithLayoutCallbackMixin,
24+
RenderAbstractLayoutBuilderMixin<BoxConstraints, RenderBox> {
25+
@override
26+
double? computeDistanceToActualBaseline(TextBaseline baseline) {
27+
return child?.getDistanceToActualBaseline(baseline) ??
28+
super.computeDistanceToActualBaseline(baseline);
29+
}
30+
31+
@override
32+
double? computeDryBaseline(
33+
BoxConstraints constraints, TextBaseline baseline) {
34+
return null;
35+
}
36+
37+
@override
38+
Size computeDryLayout(BoxConstraints constraints) {
39+
return Size.zero;
40+
}
41+
42+
@override
43+
double computeMaxIntrinsicHeight(double width) {
44+
return 0.0;
45+
}
46+
47+
@override
48+
double computeMaxIntrinsicWidth(double height) {
49+
return 0.0;
50+
}
51+
52+
@override
53+
double computeMinIntrinsicHeight(double width) {
54+
return 0.0;
55+
}
56+
57+
@override
58+
double computeMinIntrinsicWidth(double height) {
59+
return 0.0;
60+
}
61+
62+
@override
63+
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) {
64+
return child?.hitTest(result, position: position) ?? false;
65+
}
66+
67+
@override
68+
void paint(PaintingContext context, Offset offset) {
69+
if (child != null) {
70+
context.paintChild(child!, offset);
71+
}
72+
}
73+
74+
@override
75+
void performLayout() {
76+
final constraints = this.constraints;
77+
runLayoutCallback();
78+
if (child != null) {
79+
child!.layout(constraints, parentUsesSize: true);
80+
size = constraints.constrain(child!.size);
81+
} else {
82+
size = constraints.biggest;
83+
}
84+
}
85+
}

packages/core/test/_.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,15 +607,16 @@ class Explainer {
607607
return _widget(widget.builder(context));
608608
}
609609

610-
if (widget is LayoutBuilder) {
610+
if (widget is LayoutBuilder ||
611+
widget.runtimeType.toString() == 'HtmlLayoutBuilder') {
611612
return _widget(
612-
widget.builder(
613+
(widget as dynamic).builder(
613614
context,
614615
BoxConstraints.loose(
615616
TestWidgetsFlutterBinding
616617
.instance.platformDispatcher.implicitView!.physicalSize,
617618
),
618-
),
619+
) as Widget,
619620
);
620621
}
621622

0 commit comments

Comments
 (0)