@@ -104,6 +104,7 @@ class TextParser extends StatelessWidget {
104
104
this .emoteSize,
105
105
this .setCodeLanguage,
106
106
this .getCodeLanguage,
107
+ this .inlineSpanEnd,
107
108
});
108
109
109
110
final double indentSize = 10.0 ;
@@ -125,6 +126,7 @@ class TextParser extends StatelessWidget {
125
126
final double ? emoteSize;
126
127
final SetCodeLanguage ? setCodeLanguage;
127
128
final GetCodeLanguage ? getCodeLanguage;
129
+ final InlineSpan ? inlineSpanEnd;
128
130
129
131
TextSpan _parseTextNode (
130
132
BuildContext context, ParseContext parseContext, dom.Text node) {
@@ -948,8 +950,11 @@ class TextParser extends StatelessWidget {
948
950
textStyle: defaultTextStyle,
949
951
linkStyle: linkStyle,
950
952
);
951
- final widget =
952
- _parseNode (context, parseContext, parser.parseFragment (data));
953
+ final nodeParsed = _parseNode (context, parseContext, parser.parseFragment (data));
954
+ final widget = inlineSpanEnd != null
955
+ ? _addInlineSpanToNode (inlineSpan: _optimizeTextspan (inlineSpanEnd! ), nodeParsed: nodeParsed)
956
+ : nodeParsed;
957
+
953
958
if (shrinkToFit) {
954
959
return widget;
955
960
}
@@ -958,6 +963,84 @@ class TextParser extends StatelessWidget {
958
963
child: widget,
959
964
);
960
965
}
966
+
967
+ Widget _addInlineSpanToNode ({required InlineSpan inlineSpan, required Widget nodeParsed}) {
968
+ if (nodeParsed is CleanRichText ) {
969
+ return _addInlineSpanToCleanRichText (inlineSpan: inlineSpan, richText: nodeParsed);
970
+ } else if (nodeParsed is Column && nodeParsed.children.isNotEmpty) {
971
+ return _addInlineSpanToColumn (inlineSpan: inlineSpan, column: nodeParsed);
972
+ } else {
973
+ return CleanRichText (
974
+ TextSpan (
975
+ children: [
976
+ WidgetSpan (child: nodeParsed),
977
+ inlineSpan
978
+ ]
979
+ ),
980
+ maxLines: maxLines
981
+ );
982
+ }
983
+ }
984
+
985
+ Widget _addInlineSpanToCleanRichText ({required InlineSpan inlineSpan, required CleanRichText richText}) {
986
+ final childRichText = richText.child;
987
+ if (childRichText is TextSpan ) {
988
+ return CleanRichText (
989
+ TextSpan (
990
+ text: childRichText.text,
991
+ children: [
992
+ if (childRichText.children != null )
993
+ ...childRichText.children! ,
994
+ inlineSpan
995
+ ]
996
+ ),
997
+ maxLines: richText.maxLines,
998
+ textAlign: richText.textAlign,
999
+ );
1000
+ } else {
1001
+ return CleanRichText (
1002
+ TextSpan (
1003
+ children: [
1004
+ childRichText,
1005
+ inlineSpan
1006
+ ]
1007
+ ),
1008
+ maxLines: richText.maxLines,
1009
+ textAlign: richText.textAlign,
1010
+ );
1011
+ }
1012
+ }
1013
+
1014
+ Widget _addInlineSpanToColumn ({required InlineSpan inlineSpan, required Column column}) {
1015
+ final columnChildren = column.children;
1016
+ final lastChild = columnChildren.removeLast ();
1017
+ Widget newLastChild;
1018
+ if (lastChild is CleanRichText ) {
1019
+ newLastChild = _addInlineSpanToCleanRichText (inlineSpan: inlineSpan, richText: lastChild);
1020
+ } else {
1021
+ newLastChild = CleanRichText (
1022
+ TextSpan (
1023
+ children: [
1024
+ WidgetSpan (child: lastChild),
1025
+ inlineSpan
1026
+ ]
1027
+ ),
1028
+ maxLines: maxLines
1029
+ );
1030
+ }
1031
+ return Column (
1032
+ crossAxisAlignment: column.crossAxisAlignment,
1033
+ mainAxisAlignment: column.mainAxisAlignment,
1034
+ mainAxisSize: column.mainAxisSize,
1035
+ textDirection: column.textDirection,
1036
+ textBaseline: column.textBaseline,
1037
+ verticalDirection: column.verticalDirection,
1038
+ children: [
1039
+ ...columnChildren,
1040
+ newLastChild
1041
+ ]
1042
+ );
1043
+ }
961
1044
}
962
1045
963
1046
class ParseContext {
0 commit comments