@@ -151,6 +151,7 @@ class HtmlRichTextParser extends StatelessWidget {
151
151
),
152
152
this .imageProperties,
153
153
this .onImageTap,
154
+ this .showImages = true ,
154
155
});
155
156
156
157
final double indentSize = 10.0 ;
@@ -165,6 +166,7 @@ class HtmlRichTextParser extends StatelessWidget {
165
166
final TextStyle linkStyle;
166
167
final ImageProperties imageProperties;
167
168
final OnImageTap onImageTap;
169
+ final bool showImages;
168
170
169
171
// style elements set a default style
170
172
// for all child nodes
@@ -615,86 +617,88 @@ class HtmlRichTextParser extends StatelessWidget {
615
617
parseContext.rootWidgetList.add (Divider (height: 1.0 , color: Colors .black38));
616
618
break ;
617
619
case "img" :
618
- if (node.attributes['src' ] != null ) {
619
- if (node.attributes['src' ].startsWith ("data:image" ) &&
620
- node.attributes['src' ].contains ("base64," )) {
621
- precacheImage (
622
- MemoryImage (
623
- base64.decode (
624
- node.attributes['src' ].split ("base64," )[1 ].trim (),
620
+ if (showImages) {
621
+ if (node.attributes['src' ] != null ) {
622
+ if (node.attributes['src' ].startsWith ("data:image" ) &&
623
+ node.attributes['src' ].contains ("base64," )) {
624
+ precacheImage (
625
+ MemoryImage (
626
+ base64.decode (
627
+ node.attributes['src' ].split ("base64," )[1 ].trim (),
628
+ ),
625
629
),
626
- ) ,
627
- buildContext ,
628
- onError : onImageError,
629
- );
630
- parseContext.rootWidgetList. add ( GestureDetector (
631
- child : Image . memory (
632
- base64. decode (node.attributes[ 'src' ]. split ( "base64," )[ 1 ]. trim ()),
633
- width : imageProperties ? . width ??
634
- (( node.attributes['width' ] != null )
635
- ? double . parse (node.attributes[ 'width' ])
636
- : null ),
637
- height : imageProperties ? . height ??
638
- (( node.attributes['height' ] != null )
639
- ? double . parse (node.attributes[ 'height' ])
640
- : null ) ,
641
- scale : imageProperties? .scale ?? 1.0 ,
642
- matchTextDirection : imageProperties? .matchTextDirection ?? false ,
643
- centerSlice : imageProperties? .centerSlice ,
644
- filterQuality : imageProperties? .filterQuality ?? FilterQuality .low ,
645
- alignment : imageProperties? .alignment ?? Alignment .center ,
646
- colorBlendMode : imageProperties? .colorBlendMode ,
647
- fit : imageProperties? .fit ,
648
- color : imageProperties? .color ,
649
- repeat : imageProperties? .repeat ?? ImageRepeat .noRepeat ,
650
- semanticLabel : imageProperties? .semanticLabel,
651
- excludeFromSemantics : (imageProperties ? .semanticLabel == null ) ? true : false ,
652
- ) ,
653
- onTap : onImageTap,
654
- ));
655
- } else {
656
- precacheImage (
657
- NetworkImage (node.attributes[ 'src' ]) ,
658
- buildContext ,
659
- onError : onImageError,
660
- );
661
- parseContext.rootWidgetList. add ( GestureDetector (
662
- child : Image . network (
663
- node.attributes[ 'src' ],
664
- width : imageProperties ? . width ??
665
- (( node.attributes['width' ] != null )
666
- ? double . parse (node.attributes[ 'width' ])
667
- : null ),
668
- height : imageProperties ? . height ??
669
- (( node.attributes['height' ] != null )
670
- ? double . parse (node.attributes[ 'height' ])
671
- : null ) ,
672
- scale : imageProperties? .scale ?? 1.0 ,
673
- matchTextDirection : imageProperties? .matchTextDirection ?? false ,
674
- centerSlice : imageProperties? .centerSlice ,
675
- filterQuality : imageProperties? .filterQuality ?? FilterQuality .low ,
676
- alignment : imageProperties? .alignment ?? Alignment .center ,
677
- colorBlendMode : imageProperties? .colorBlendMode ,
678
- fit : imageProperties? .fit ,
679
- color : imageProperties? .color ,
680
- repeat : imageProperties? .repeat ?? ImageRepeat .noRepeat ,
681
- semanticLabel : imageProperties? .semanticLabel,
682
- excludeFromSemantics : (imageProperties ? .semanticLabel == null ) ? true : false ,
683
- ) ,
684
- onTap : onImageTap,
685
- ));
686
- }
687
- if (node.attributes[ 'alt' ] != null ) {
688
- parseContext.rootWidgetList. add ( BlockText (
689
- margin : EdgeInsets .symmetric (horizontal : 0.0 , vertical : 10 .0 ),
690
- padding : EdgeInsets . all ( 0.0 ),
691
- child : RichText (
692
- textAlign : TextAlign .center,
693
- text: TextSpan (
694
- text : node.attributes[ 'alt' ] ,
695
- style : nextContext.childStyle ,
696
- children : < TextSpan > [],
697
- ))));
630
+ buildContext ,
631
+ onError : onImageError ,
632
+ );
633
+ parseContext.rootWidgetList. add ( GestureDetector (
634
+ child : Image . memory (
635
+ base64. decode (node.attributes[ 'src' ]. split ( "base64," )[ 1 ]. trim ()),
636
+ width : imageProperties ? .width ??
637
+ ((node.attributes[ ' width' ] != null )
638
+ ? double . parse ( node.attributes['width' ])
639
+ : null ),
640
+ height : imageProperties ? .height ??
641
+ ((node.attributes[ ' height' ] != null )
642
+ ? double . parse ( node.attributes['height' ])
643
+ : null ),
644
+ scale : imageProperties ? .scale ?? 1.0 ,
645
+ matchTextDirection : imageProperties? .matchTextDirection ?? false ,
646
+ centerSlice : imageProperties? .centerSlice ,
647
+ filterQuality : imageProperties? .filterQuality ?? FilterQuality .low ,
648
+ alignment : imageProperties? .alignment ?? Alignment .center ,
649
+ colorBlendMode : imageProperties? .colorBlendMode ,
650
+ fit : imageProperties? .fit ,
651
+ color : imageProperties? .color ,
652
+ repeat : imageProperties? .repeat ?? ImageRepeat .noRepeat ,
653
+ semanticLabel : imageProperties? .semanticLabel ,
654
+ excludeFromSemantics : ( imageProperties? .semanticLabel == null ) ? true : false ,
655
+ ) ,
656
+ onTap : onImageTap ,
657
+ ));
658
+ } else {
659
+ precacheImage (
660
+ NetworkImage (node.attributes[ 'src' ]),
661
+ buildContext ,
662
+ onError : onImageError ,
663
+ );
664
+ parseContext.rootWidgetList. add ( GestureDetector (
665
+ child : Image . network (
666
+ node.attributes[ 'src' ],
667
+ width : imageProperties ? .width ??
668
+ ((node.attributes[ ' width' ] != null )
669
+ ? double . parse ( node.attributes['width' ])
670
+ : null ),
671
+ height : imageProperties ? .height ??
672
+ ((node.attributes[ ' height' ] != null )
673
+ ? double . parse ( node.attributes['height' ])
674
+ : null ),
675
+ scale : imageProperties ? .scale ?? 1.0 ,
676
+ matchTextDirection : imageProperties? .matchTextDirection ?? false ,
677
+ centerSlice : imageProperties? .centerSlice ,
678
+ filterQuality : imageProperties? .filterQuality ?? FilterQuality .low ,
679
+ alignment : imageProperties? .alignment ?? Alignment .center ,
680
+ colorBlendMode : imageProperties? .colorBlendMode ,
681
+ fit : imageProperties? .fit ,
682
+ color : imageProperties? .color ,
683
+ repeat : imageProperties? .repeat ?? ImageRepeat .noRepeat ,
684
+ semanticLabel : imageProperties? .semanticLabel ,
685
+ excludeFromSemantics : ( imageProperties? .semanticLabel == null ) ? true : false ,
686
+ ) ,
687
+ onTap : onImageTap ,
688
+ ));
689
+ }
690
+ if (node.attributes[ 'alt' ] != null ) {
691
+ parseContext.rootWidgetList. add ( BlockText (
692
+ margin : EdgeInsets . symmetric (horizontal : 0.0 , vertical : 10.0 ),
693
+ padding : EdgeInsets .all ( 0 .0 ),
694
+ child : RichText (
695
+ textAlign : TextAlign .center,
696
+ text : TextSpan (
697
+ text: node.attributes[ 'alt' ],
698
+ style : nextContext.childStyle ,
699
+ children : < TextSpan > [] ,
700
+ ))));
701
+ }
698
702
}
699
703
}
700
704
break ;
@@ -876,6 +880,7 @@ class HtmlOldParser extends StatelessWidget {
876
880
decoration: TextDecoration .underline,
877
881
color: Colors .blueAccent,
878
882
decorationColor: Colors .blueAccent),
883
+ this .showImages = true ,
879
884
});
880
885
881
886
final double width;
@@ -886,6 +891,7 @@ class HtmlOldParser extends StatelessWidget {
886
891
final String html;
887
892
final ImageErrorListener onImageError;
888
893
final TextStyle linkStyle;
894
+ final bool showImages;
889
895
890
896
static const _supportedElements = [
891
897
"a" ,
@@ -1345,30 +1351,32 @@ class HtmlOldParser extends StatelessWidget {
1345
1351
case "img" :
1346
1352
return Builder (
1347
1353
builder: (BuildContext context) {
1348
- if (node.attributes['src' ] != null ) {
1349
- if (node.attributes['src' ].startsWith ("data:image" ) &&
1350
- node.attributes['src' ].contains ("base64," )) {
1354
+ if (showImages) {
1355
+ if (node.attributes['src' ] != null ) {
1356
+ if (node.attributes['src' ].startsWith ("data:image" ) &&
1357
+ node.attributes['src' ].contains ("base64," )) {
1358
+ precacheImage (
1359
+ MemoryImage (base64.decode (node.attributes['src' ].split ("base64," )[1 ].trim ())),
1360
+ context,
1361
+ onError: onImageError,
1362
+ );
1363
+ return Image .memory (
1364
+ base64.decode (node.attributes['src' ].split ("base64," )[1 ].trim ()));
1365
+ }
1351
1366
precacheImage (
1352
- MemoryImage (base64. decode ( node.attributes['src' ]. split ( "base64," )[ 1 ]. trim ()) ),
1367
+ NetworkImage ( node.attributes['src' ]),
1353
1368
context,
1354
1369
onError: onImageError,
1355
1370
);
1356
- return Image .memory (
1357
- base64.decode (node.attributes['src' ].split ("base64," )[1 ].trim ()));
1358
- }
1359
- precacheImage (
1360
- NetworkImage (node.attributes['src' ]),
1361
- context,
1362
- onError: onImageError,
1363
- );
1364
- return Image .network (node.attributes['src' ]);
1365
- } else if (node.attributes['alt' ] != null ) {
1366
- //Temp fix for https://github.com/flutter/flutter/issues/736
1367
- if (node.attributes['alt' ].endsWith (" " )) {
1368
- return Container (
1369
- padding: EdgeInsets .only (right: 2.0 ), child: Text (node.attributes['alt' ]));
1370
- } else {
1371
- return Text (node.attributes['alt' ]);
1371
+ return Image .network (node.attributes['src' ]);
1372
+ } else if (node.attributes['alt' ] != null ) {
1373
+ //Temp fix for https://github.com/flutter/flutter/issues/736
1374
+ if (node.attributes['alt' ].endsWith (" " )) {
1375
+ return Container (
1376
+ padding: EdgeInsets .only (right: 2.0 ), child: Text (node.attributes['alt' ]));
1377
+ } else {
1378
+ return Text (node.attributes['alt' ]);
1379
+ }
1372
1380
}
1373
1381
}
1374
1382
return Container ();
0 commit comments