@@ -263,36 +263,45 @@ class DetailsContentElement extends LayoutElement {
263263
264264 @override
265265 Widget toWidget (RenderContext context) {
266+ List <InlineSpan > childrenList = children? .map ((tree) => context.parser.parseTree (context, tree))? .toList ();
267+ List <InlineSpan > toRemove = [];
268+ if (childrenList != null ) {
269+ for (InlineSpan child in childrenList) {
270+ if (child is TextSpan && child.text != null && child.text.trim ().isEmpty) {
271+ toRemove.add (child);
272+ }
273+ }
274+ for (InlineSpan child in toRemove) {
275+ childrenList.remove (child);
276+ }
277+ }
278+ InlineSpan firstChild = childrenList? .isNotEmpty == true ? childrenList.first : null ;
266279 return ExpansionTile (
267- title: children != null && elementList.first.localName == "summary" ? StyledText (
280+ title: elementList ? .isNotEmpty == true && elementList? .first? .localName == "summary" ? StyledText (
268281 textSpan: TextSpan (
269282 style: style.generateTextStyle (),
270- children: [children
271- .map ((tree) => context.parser.parseTree (context, tree))
272- .toList ().first] ??
273- [],
283+ children: [firstChild] ?? [],
274284 ),
275285 style: style,
276286 ) : Text ("Details" ),
277287 children: [
278288 StyledText (
279289 textSpan: TextSpan (
280290 style: style.generateTextStyle (),
281- children: getChildren (children , context)
291+ children: getChildren (childrenList , context, elementList ? .isNotEmpty == true && elementList ? .first ? .localName == "summary" ? firstChild : null )
282292 ),
283293 style: style,
284294 ),
285295 ]
286296 );
287297 }
288298
289- List <InlineSpan > getChildren (List <StyledElement > children, RenderContext context) {
290- if (children. map ((tree) => context.parser. parseTree (context, tree)). toList () == null ) {
299+ List <InlineSpan > getChildren (List <InlineSpan > children, RenderContext context, InlineSpan firstChild ) {
300+ if (children == null ) {
291301 return [];
292302 } else {
293- List <InlineSpan > reducedChildren = children.map ((tree) => context.parser.parseTree (context, tree)).toList ();
294- reducedChildren.removeAt (0 );
295- return reducedChildren;
303+ if (firstChild != null ) children.removeAt (0 );
304+ return children;
296305 }
297306 }
298307}
0 commit comments