@@ -263,36 +263,45 @@ class DetailsContentElement extends LayoutElement {
263
263
264
264
@override
265
265
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 ;
266
279
return ExpansionTile (
267
- title: children != null && elementList.first.localName == "summary" ? StyledText (
280
+ title: elementList ? .isNotEmpty == true && elementList? .first? .localName == "summary" ? StyledText (
268
281
textSpan: TextSpan (
269
282
style: style.generateTextStyle (),
270
- children: [children
271
- .map ((tree) => context.parser.parseTree (context, tree))
272
- .toList ().first] ??
273
- [],
283
+ children: [firstChild] ?? [],
274
284
),
275
285
style: style,
276
286
) : Text ("Details" ),
277
287
children: [
278
288
StyledText (
279
289
textSpan: TextSpan (
280
290
style: style.generateTextStyle (),
281
- children: getChildren (children , context)
291
+ children: getChildren (childrenList , context, elementList ? .isNotEmpty == true && elementList ? .first ? .localName == "summary" ? firstChild : null )
282
292
),
283
293
style: style,
284
294
),
285
295
]
286
296
);
287
297
}
288
298
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 ) {
291
301
return [];
292
302
} 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;
296
305
}
297
306
}
298
307
}
0 commit comments