@@ -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) {
@@ -960,8 +962,11 @@ class TextParser extends StatelessWidget {
960
962
textStyle: defaultTextStyle,
961
963
linkStyle: linkStyle,
962
964
);
963
- final widget =
964
- _parseNode (context, parseContext, parser.parseFragment (data));
965
+ final nodeParsed = _parseNode (context, parseContext, parser.parseFragment (data));
966
+ final widget = inlineSpanEnd != null
967
+ ? _addInlineSpanToNode (inlineSpan: _optimizeTextspan (inlineSpanEnd! ), nodeParsed: nodeParsed)
968
+ : nodeParsed;
969
+
965
970
if (shrinkToFit) {
966
971
return widget;
967
972
}
@@ -970,6 +975,92 @@ class TextParser extends StatelessWidget {
970
975
child: widget,
971
976
);
972
977
}
978
+
979
+ Widget _addInlineSpanToNode ({required InlineSpan inlineSpan, required Widget nodeParsed}) {
980
+ if (nodeParsed is CleanRichText ) {
981
+ return _addInlineSpanToCleanRichText (inlineSpan: inlineSpan, richText: nodeParsed);
982
+ } else if (nodeParsed is Column && nodeParsed.children.isNotEmpty) {
983
+ return _addInlineSpanToColumn (inlineSpan: inlineSpan, column: nodeParsed);
984
+ } else {
985
+ return CleanRichText (
986
+ TextSpan (
987
+ children: [
988
+ WidgetSpan (child: nodeParsed),
989
+ inlineSpan
990
+ ]
991
+ ),
992
+ maxLines: maxLines
993
+ );
994
+ }
995
+ }
996
+
997
+ Widget _addInlineSpanToCleanRichText ({required InlineSpan inlineSpan, required CleanRichText richText}) {
998
+ final childRichText = richText.child;
999
+ if (childRichText is TextSpan ) {
1000
+ return CleanRichText (
1001
+ TextSpan (
1002
+ text: childRichText.text,
1003
+ style: childRichText.style,
1004
+ recognizer: childRichText.recognizer,
1005
+ mouseCursor: childRichText.mouseCursor,
1006
+ onEnter: childRichText.onEnter,
1007
+ onExit: childRichText.onExit,
1008
+ semanticsLabel: childRichText.semanticsLabel,
1009
+ locale: childRichText.locale,
1010
+ spellOut: childRichText.spellOut,
1011
+ children: [
1012
+ if (childRichText.children != null )
1013
+ ...childRichText.children! ,
1014
+ inlineSpan
1015
+ ]
1016
+ ),
1017
+ maxLines: richText.maxLines,
1018
+ textAlign: richText.textAlign,
1019
+ );
1020
+ } else {
1021
+ return CleanRichText (
1022
+ TextSpan (
1023
+ children: [
1024
+ childRichText,
1025
+ inlineSpan
1026
+ ]
1027
+ ),
1028
+ maxLines: richText.maxLines,
1029
+ textAlign: richText.textAlign,
1030
+ );
1031
+ }
1032
+ }
1033
+
1034
+ Widget _addInlineSpanToColumn ({required InlineSpan inlineSpan, required Column column}) {
1035
+ final columnChildren = column.children;
1036
+ final lastChild = columnChildren.removeLast ();
1037
+ Widget newLastChild;
1038
+ if (lastChild is CleanRichText ) {
1039
+ newLastChild = _addInlineSpanToCleanRichText (inlineSpan: inlineSpan, richText: lastChild);
1040
+ } else {
1041
+ newLastChild = CleanRichText (
1042
+ TextSpan (
1043
+ children: [
1044
+ WidgetSpan (child: lastChild),
1045
+ inlineSpan
1046
+ ]
1047
+ ),
1048
+ maxLines: maxLines
1049
+ );
1050
+ }
1051
+ return Column (
1052
+ crossAxisAlignment: column.crossAxisAlignment,
1053
+ mainAxisAlignment: column.mainAxisAlignment,
1054
+ mainAxisSize: column.mainAxisSize,
1055
+ textDirection: column.textDirection,
1056
+ textBaseline: column.textBaseline,
1057
+ verticalDirection: column.verticalDirection,
1058
+ children: [
1059
+ ...columnChildren,
1060
+ newLastChild
1061
+ ]
1062
+ );
1063
+ }
973
1064
}
974
1065
975
1066
class ParseContext {
0 commit comments