diff --git a/lib/src/models/documents/nodes/line.dart b/lib/src/models/documents/nodes/line.dart index 2a118785..fa5f6c90 100644 --- a/lib/src/models/documents/nodes/line.dart +++ b/lib/src/models/documents/nodes/line.dart @@ -26,11 +26,7 @@ class Line extends Container { /// Returns `true` if this line contains an embedded object. bool get hasEmbed { - if (childCount != 1) { - return false; - } - - return children.single is Embed; + return children.any((child) => child is Embed); } /// Returns next [Line] or `null` if this is the last line in the document. diff --git a/lib/src/widgets/text_line.dart b/lib/src/widgets/text_line.dart index 45004916..049e73c8 100644 --- a/lib/src/widgets/text_line.dart +++ b/lib/src/widgets/text_line.dart @@ -39,12 +39,17 @@ class TextLine extends StatelessWidget { Widget build(BuildContext context) { assert(debugCheckHasMediaQuery(context)); - // In rare circumstances, the line could contain an Embed & a Text of - // newline, which is unexpected and probably we should find out the - // root cause - final childCount = line.childCount; - if (line.hasEmbed || (childCount > 1 && line.children.first is Embed)) { - final embed = line.children.first as Embed; + if (line.hasEmbed) { + if (line.childCount == 1) { + // For video, it is always single child + final embed = line.children.single as Embed; + return EmbedProxy(embedBuilder(context, embed, readOnly)); + } + + // The line could contain more than one Embed & more than one Text + // TODO: handle more than one Embed + final embed = + line.children.firstWhere((child) => child is Embed) as Embed; return EmbedProxy(embedBuilder(context, embed, readOnly)); }