From f5c2bdcee5ea37c7fe81dda2d66ce203b1442281 Mon Sep 17 00:00:00 2001 From: dev-kuma <69457983+dev-kuma@users.noreply.github.com> Date: Wed, 19 Aug 2020 16:30:27 +0800 Subject: [PATCH 1/2] Added support to skip custom render-er if is null These changes allow skipping the custom render-er and using back the default render-er in some cases, by returning a null value or not returning any value from the function "customRender". --- lib/html_parser.dart | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/html_parser.dart b/lib/html_parser.dart index eaea326d64..41cfdcaedf 100644 --- a/lib/html_parser.dart +++ b/lib/html_parser.dart @@ -224,27 +224,31 @@ class HtmlParser extends StatelessWidget { ); if (customRender?.containsKey(tree.name) ?? false) { - return WidgetSpan( - child: ContainerSpan( + dynamic customRenderForElement = customRender[tree.name].call( + newContext, + ContainerSpan( newContext: newContext, style: tree.style, shrinkWrap: context.parser.shrinkWrap, - child: customRender[tree.name].call( - newContext, - ContainerSpan( - newContext: newContext, - style: tree.style, - shrinkWrap: context.parser.shrinkWrap, - children: tree.children - ?.map((tree) => parseTree(newContext, tree)) - ?.toList() ?? - [], - ), - tree.attributes, - tree.element, - ), + children: tree.children + ?.map((tree) => parseTree(newContext, tree)) + ?.toList() ?? + [], ), + tree.attributes, + tree.element, ); + + if (customRenderForElement != null) { + return WidgetSpan( + child: ContainerSpan( + newContext: newContext, + style: tree.style, + shrinkWrap: context.parser.shrinkWrap, + child: builder, + ), + ); + } } //Return the correct InlineSpan based on the element type. From 488acc1f0f3ae2e836336cfff041932e6bcaafe8 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Thu, 19 Nov 2020 12:41:59 +0100 Subject: [PATCH 2/2] Fix custom renderer not being applied at all --- lib/html_parser.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/html_parser.dart b/lib/html_parser.dart index ef31f38c1d..882d60e5ea 100644 --- a/lib/html_parser.dart +++ b/lib/html_parser.dart @@ -245,7 +245,7 @@ class HtmlParser extends StatelessWidget { newContext: newContext, style: tree.style, shrinkWrap: context.parser.shrinkWrap, - child: builder, + child: customRenderForElement, ), ); }