From 06a7f4aa2e0150b4fac4123505f7af6ce0d498b8 Mon Sep 17 00:00:00 2001 From: hyouuu Date: Wed, 2 Jun 2021 00:17:27 -0700 Subject: [PATCH] Fix a bug that Embed could be together with Text (#249) --- lib/src/widgets/text_line.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/src/widgets/text_line.dart b/lib/src/widgets/text_line.dart index d95923d3..c258acc0 100644 --- a/lib/src/widgets/text_line.dart +++ b/lib/src/widgets/text_line.dart @@ -37,8 +37,14 @@ class TextLine extends StatelessWidget { Widget build(BuildContext context) { assert(debugCheckHasMediaQuery(context)); - if (line.hasEmbed) { - final embed = line.children.single as Embed; + // 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; return EmbedProxy(embedBuilder(context, embed)); }