|
|
|
@ -10,6 +10,7 @@ import 'package:url_launcher/url_launcher.dart'; |
|
|
|
|
|
|
|
|
|
import '../models/documents/attribute.dart'; |
|
|
|
|
import '../models/documents/nodes/container.dart' as container_node; |
|
|
|
|
import '../models/documents/nodes/embeddable.dart'; |
|
|
|
|
import '../models/documents/nodes/leaf.dart'; |
|
|
|
|
import '../models/documents/nodes/leaf.dart' as leaf; |
|
|
|
|
import '../models/documents/nodes/line.dart'; |
|
|
|
@ -132,17 +133,28 @@ class _TextLineState extends State<TextLine> { |
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
assert(debugCheckHasMediaQuery(context)); |
|
|
|
|
|
|
|
|
|
if (widget.line.hasEmbed && widget.line.childCount == 1) { |
|
|
|
|
// For video, it is always single child |
|
|
|
|
final embed = widget.line.children.single as Embed; |
|
|
|
|
return EmbedProxy( |
|
|
|
|
widget.embedBuilder( |
|
|
|
|
context, |
|
|
|
|
widget.controller, |
|
|
|
|
embed, |
|
|
|
|
widget.readOnly, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
// Single child embeds can be expanded |
|
|
|
|
var embed = widget.line.children.single as Embed; |
|
|
|
|
// Creates correct node for custom embed |
|
|
|
|
if (embed.value.type == BlockEmbed.customType) { |
|
|
|
|
embed = Embed(CustomBlockEmbed.fromJsonString(embed.value.data)); |
|
|
|
|
} |
|
|
|
|
final embedBuilder = widget.embedBuilder(embed); |
|
|
|
|
if (embedBuilder.expanded) { |
|
|
|
|
// Creates correct node for custom embed |
|
|
|
|
|
|
|
|
|
return EmbedProxy( |
|
|
|
|
embedBuilder.build( |
|
|
|
|
context, |
|
|
|
|
widget.controller, |
|
|
|
|
embed, |
|
|
|
|
widget.readOnly, |
|
|
|
|
false, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
final textSpan = _getTextSpanForWholeLine(context); |
|
|
|
|
final strutStyle = StrutStyle.fromTextStyle(textSpan.style!); |
|
|
|
@ -173,24 +185,28 @@ class _TextLineState extends State<TextLine> { |
|
|
|
|
// The line could contain more than one Embed & more than one Text |
|
|
|
|
final textSpanChildren = <InlineSpan>[]; |
|
|
|
|
var textNodes = LinkedList<Node>(); |
|
|
|
|
for (final child in widget.line.children) { |
|
|
|
|
for (var child in widget.line.children) { |
|
|
|
|
if (child is Embed) { |
|
|
|
|
if (textNodes.isNotEmpty) { |
|
|
|
|
textSpanChildren |
|
|
|
|
.add(_buildTextSpan(widget.styles, textNodes, lineStyle)); |
|
|
|
|
textNodes = LinkedList<Node>(); |
|
|
|
|
} |
|
|
|
|
// Here it should be image |
|
|
|
|
final embed = WidgetSpan( |
|
|
|
|
child: EmbedProxy( |
|
|
|
|
widget.embedBuilder( |
|
|
|
|
context, |
|
|
|
|
widget.controller, |
|
|
|
|
child, |
|
|
|
|
widget.readOnly, |
|
|
|
|
), |
|
|
|
|
// Creates correct node for custom embed |
|
|
|
|
if (child.value.type == BlockEmbed.customType) { |
|
|
|
|
child = Embed(CustomBlockEmbed.fromJsonString(child.value.data)); |
|
|
|
|
} |
|
|
|
|
final embedBuilder = widget.embedBuilder(child); |
|
|
|
|
final embedWidget = EmbedProxy( |
|
|
|
|
embedBuilder.build( |
|
|
|
|
context, |
|
|
|
|
widget.controller, |
|
|
|
|
child, |
|
|
|
|
widget.readOnly, |
|
|
|
|
true, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
final embed = embedBuilder.buildWidgetSpan(embedWidget); |
|
|
|
|
textSpanChildren.add(embed); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|