Skip to content

Commit 65c434d

Browse files
committed
WIP: Compute margins and cleanup
1 parent d87ef3a commit 65c434d

14 files changed

+268
-155
lines changed

lib/custom_render.dart

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ CustomRender blockElementRender({Style? style, List<InlineSpan>? children}) =>
116116
children: (children as List<TextSpan>?) ??
117117
context.tree.children
118118
.expandIndexed((i, childTree) => [
119-
if (childTree.style.display == Display.BLOCK &&
120-
i > 0 &&
121-
context.tree.children[i - 1] is ReplacedElement)
122-
TextSpan(text: "\n"),
123119
context.parser.parseTree(context, childTree),
124120
if (i != context.tree.children.length - 1 &&
125121
childTree.style.display == Display.BLOCK &&
@@ -133,17 +129,12 @@ CustomRender blockElementRender({Style? style, List<InlineSpan>? children}) =>
133129
return WidgetSpan(
134130
child: ContainerSpan(
135131
key: context.key,
136-
newContext: context,
132+
renderContext: context,
137133
style: style ?? context.tree.style,
138134
shrinkWrap: context.parser.shrinkWrap,
139135
children: children ??
140136
context.tree.children
141137
.expandIndexed((i, childTree) => [
142-
if (context.parser.shrinkWrap &&
143-
childTree.style.display == Display.BLOCK &&
144-
i > 0 &&
145-
context.tree.children[i - 1] is ReplacedElement)
146-
TextSpan(text: "\n"),
147138
context.parser.parseTree(context, childTree),
148139
if (i != context.tree.children.length - 1 &&
149140
childTree.style.display == Display.BLOCK &&
@@ -161,7 +152,7 @@ CustomRender listElementRender(
161152
inlineSpan: (context, buildChildren) => WidgetSpan(
162153
child: ContainerSpan(
163154
key: context.key,
164-
newContext: context,
155+
renderContext: context,
165156
style: style ?? context.tree.style,
166157
shrinkWrap: context.parser.shrinkWrap,
167158
child: Row(

lib/flutter_html.dart

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,26 @@ class _HtmlState extends State<Html> {
179179
Widget build(BuildContext context) {
180180
return Container(
181181
width: widget.shrinkWrap ? null : MediaQuery.of(context).size.width,
182-
child: HtmlParser(
183-
key: widget._anchorKey,
184-
htmlData: documentElement,
185-
onLinkTap: widget.onLinkTap,
186-
onAnchorTap: widget.onAnchorTap,
187-
onImageTap: widget.onImageTap,
188-
onCssParseError: widget.onCssParseError,
189-
onImageError: widget.onImageError,
190-
shrinkWrap: widget.shrinkWrap,
191-
selectable: false,
192-
style: widget.style,
193-
customRenders: {}
194-
..addAll(widget.customRenders)
195-
..addAll(defaultRenders),
196-
tagsList: widget.tagsList.isEmpty ? Html.tags : widget.tagsList,
182+
child: LayoutBuilder(
183+
builder: (context, constraints) {
184+
return HtmlParser(
185+
key: widget._anchorKey,
186+
htmlData: documentElement,
187+
onLinkTap: widget.onLinkTap,
188+
onAnchorTap: widget.onAnchorTap,
189+
onImageTap: widget.onImageTap,
190+
onCssParseError: widget.onCssParseError,
191+
onImageError: widget.onImageError,
192+
shrinkWrap: widget.shrinkWrap,
193+
selectable: false,
194+
style: widget.style,
195+
customRenders: {}
196+
..addAll(widget.customRenders)
197+
..addAll(defaultRenders),
198+
tagsList: widget.tagsList.isEmpty ? Html.tags : widget.tagsList,
199+
constraints: constraints,
200+
);
201+
}
197202
),
198203
);
199204
}
@@ -347,24 +352,29 @@ class _SelectableHtmlState extends State<SelectableHtml> {
347352
Widget build(BuildContext context) {
348353
return Container(
349354
width: widget.shrinkWrap ? null : MediaQuery.of(context).size.width,
350-
child: HtmlParser(
351-
key: widget._anchorKey,
352-
htmlData: documentElement,
353-
onLinkTap: widget.onLinkTap,
354-
onAnchorTap: widget.onAnchorTap,
355-
onImageTap: null,
356-
onCssParseError: widget.onCssParseError,
357-
onImageError: null,
358-
shrinkWrap: widget.shrinkWrap,
359-
selectable: true,
360-
style: widget.style,
361-
customRenders: {}
362-
..addAll(widget.customRenders)
363-
..addAll(defaultRenders),
364-
tagsList:
365-
widget.tagsList.isEmpty ? SelectableHtml.tags : widget.tagsList,
366-
selectionControls: widget.selectionControls,
367-
scrollPhysics: widget.scrollPhysics,
355+
child: LayoutBuilder(
356+
builder: (context, constraints) {
357+
return HtmlParser(
358+
key: widget._anchorKey,
359+
htmlData: documentElement,
360+
onLinkTap: widget.onLinkTap,
361+
onAnchorTap: widget.onAnchorTap,
362+
onImageTap: null,
363+
onCssParseError: widget.onCssParseError,
364+
onImageError: null,
365+
shrinkWrap: widget.shrinkWrap,
366+
selectable: true,
367+
style: widget.style,
368+
customRenders: {}
369+
..addAll(widget.customRenders)
370+
..addAll(defaultRenders),
371+
tagsList:
372+
widget.tagsList.isEmpty ? SelectableHtml.tags : widget.tagsList,
373+
selectionControls: widget.selectionControls,
374+
scrollPhysics: widget.scrollPhysics,
375+
constraints: constraints,
376+
);
377+
}
368378
),
369379
);
370380
}

0 commit comments

Comments
 (0)