@@ -5,6 +5,9 @@ const _kGapVsMarker = 5.0;
55
66/// A list item widget.
77class HtmlListItem extends MultiChildRenderObjectWidget {
8+ /// The alignment of the item contents.
9+ final TextAlign ? textAlign;
10+
811 /// The directionality of the item.
912 final TextDirection textDirection;
1013
@@ -13,6 +16,7 @@ class HtmlListItem extends MultiChildRenderObjectWidget {
1316 Widget ? child,
1417 super .key,
1518 Widget ? marker,
19+ this .textAlign,
1620 required this .textDirection,
1721 }) : super (
1822 children: child != null
@@ -25,17 +29,24 @@ class HtmlListItem extends MultiChildRenderObjectWidget {
2529
2630 @override
2731 RenderObject createRenderObject (BuildContext context) =>
28- _ListItemRenderObject (textDirection: textDirection);
32+ _ListItemRenderObject (
33+ textAlign: textAlign,
34+ textDirection: textDirection,
35+ );
2936
3037 @override
3138 void debugFillProperties (DiagnosticPropertiesBuilder properties) {
3239 super .debugFillProperties (properties);
40+ properties.add (EnumProperty ('textAlign' , textAlign, defaultValue: null ));
3341 properties.add (DiagnosticsProperty ('textDirection' , textDirection));
3442 }
3543
3644 @override
37- void updateRenderObject (BuildContext context, RenderObject renderObject) =>
38- (renderObject as _ListItemRenderObject ).textDirection = textDirection;
45+ void updateRenderObject (BuildContext context, RenderObject renderObject) {
46+ renderObject as _ListItemRenderObject
47+ ..textAlign = textAlign
48+ ..textDirection = textDirection;
49+ }
3950}
4051
4152class _ListItemData extends ContainerBoxParentData <RenderBox > {}
@@ -45,8 +56,21 @@ class _ListItemRenderObject extends RenderBox
4556 ContainerRenderObjectMixin <RenderBox , _ListItemData >,
4657 RenderBoxContainerDefaultsMixin <RenderBox , _ListItemData > {
4758 _ListItemRenderObject ({
59+ TextAlign ? textAlign,
4860 required TextDirection textDirection,
49- }) : _textDirection = textDirection;
61+ }) : _textAlign = textAlign,
62+ _textDirection = textDirection;
63+
64+ TextAlign ? get textAlign => _textAlign;
65+ TextAlign ? _textAlign;
66+ set textAlign (TextAlign ? value) {
67+ if (_textAlign == value) {
68+ return ;
69+ }
70+
71+ _textAlign = value;
72+ markNeedsLayout ();
73+ }
5074
5175 TextDirection get textDirection => _textDirection;
5276 TextDirection _textDirection;
@@ -112,28 +136,35 @@ class _ListItemRenderObject extends RenderBox
112136 }
113137
114138 final childData = child.parentData! as _ListItemData ;
115- final childSize = fn (child, bc);
139+ final childConstraints = bc.maxWidth.isFinite && textAlign != null
140+ ? bc.tighten (width: bc.maxWidth)
141+ : bc;
142+ final childSize = fn (child, childConstraints);
116143 final marker = childData.nextSibling;
117144 final markerSize = marker != null ? fn (marker, bc.loosen ()) : Size .zero;
118145 final height = childSize.height > 0 ? childSize.height : markerSize.height;
119146 final size = bc.constrain (Size (childSize.width, height));
120147
121- if (identical (fn, ChildLayoutHelper .layoutChild) && marker != null ) {
122- const baseline = TextBaseline .alphabetic;
123- final markerDistance =
124- marker.getDistanceToBaseline (baseline, onlyReal: true ) ??
125- markerSize.height;
126- final childDistance =
127- child.getDistanceToBaseline (baseline, onlyReal: true ) ??
128- markerDistance;
129-
130- final markerData = marker.parentData! as _ListItemData ;
131- markerData.offset = Offset (
132- textDirection == TextDirection .ltr
133- ? - markerSize.width - _kGapVsMarker
134- : childSize.width + _kGapVsMarker,
135- childDistance - markerDistance,
136- );
148+ if (identical (fn, ChildLayoutHelper .layoutChild)) {
149+ childData.offset = Offset .zero;
150+
151+ if (marker != null ) {
152+ const baseline = TextBaseline .alphabetic;
153+ final markerDistance =
154+ marker.getDistanceToBaseline (baseline, onlyReal: true ) ??
155+ markerSize.height;
156+ final childDistance =
157+ child.getDistanceToBaseline (baseline, onlyReal: true ) ??
158+ markerDistance;
159+
160+ final markerData = marker.parentData! as _ListItemData ;
161+ markerData.offset = Offset (
162+ textDirection == TextDirection .ltr
163+ ? - markerSize.width - _kGapVsMarker
164+ : childSize.width + _kGapVsMarker,
165+ childDistance - markerDistance,
166+ );
167+ }
137168 }
138169
139170 return size;
0 commit comments