@@ -63,6 +63,17 @@ class RealRichText extends Text {
63
63
maxLines: maxLines,
64
64
locale: locale);
65
65
66
+ List <TextSpan > extractAllNestedChildren (TextSpan textSpan) {
67
+ if (textSpan.children == null || textSpan.children.length == 0 ) {
68
+ return [textSpan];
69
+ }
70
+ List <TextSpan > childrenSpan = [];
71
+ textSpan.children.forEach ((child) {
72
+ childrenSpan.addAll (extractAllNestedChildren (child));
73
+ });
74
+ return childrenSpan;
75
+ }
76
+
66
77
@override
67
78
Widget build (BuildContext context) {
68
79
final DefaultTextStyle defaultTextStyle = DefaultTextStyle .of (context);
@@ -74,10 +85,13 @@ class RealRichText extends Text {
74
85
.merge (const TextStyle (fontWeight: FontWeight .bold));
75
86
76
87
TextSpan textSpan = TextSpan (
77
- style: effectiveTextStyle,
78
- text: "" ,
79
- children: textSpanList,
80
- );
88
+ style: effectiveTextStyle,
89
+ text: "" ,
90
+ children: extractAllNestedChildren (TextSpan (
91
+ style: effectiveTextStyle,
92
+ text: "" ,
93
+ children: textSpanList,
94
+ )));
81
95
82
96
// pass the context to ImageSpan to create a ImageConfiguration
83
97
textSpan.children.forEach ((f) {
@@ -189,6 +203,12 @@ class ImageResolver {
189
203
_listener? .call (imageInfo, synchronousCall);
190
204
}
191
205
206
+ void addListening () {
207
+ if (this ._listener != null ) {
208
+ _imageStream? .addListener (_handleImageChanged);
209
+ }
210
+ }
211
+
192
212
void stopListening () {
193
213
_imageStream? .removeListener (_handleImageChanged);
194
214
}
@@ -271,6 +291,16 @@ class _RealRichRenderParagraph extends RenderParagraph {
271
291
paintImageSpan (context, offset);
272
292
}
273
293
294
+ @override
295
+ void attach (covariant Object owner) {
296
+ super .attach (owner);
297
+ text.children.forEach ((textSpan) {
298
+ if (textSpan is ImageSpan ) {
299
+ textSpan.imageResolver.addListening ();
300
+ }
301
+ });
302
+ }
303
+
274
304
@override
275
305
void detach () {
276
306
super .detach ();
0 commit comments