Update text_line for handling Embed

pull/324/head
Xin Yao 4 years ago
parent 2195c4ae3e
commit 6aaf351277
  1. 6
      lib/src/models/documents/nodes/line.dart
  2. 17
      lib/src/widgets/text_line.dart

@ -26,11 +26,7 @@ class Line extends Container<Leaf?> {
/// 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.

@ -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));
}

Loading…
Cancel
Save