@@ -217,6 +217,7 @@ class HtmlRichTextParser extends StatelessWidget {
217
217
"time" ,
218
218
"span" ,
219
219
"big" ,
220
+ "sub" ,
220
221
];
221
222
222
223
// specialty elements require unique handling
@@ -519,6 +520,13 @@ class HtmlRichTextParser extends StatelessWidget {
519
520
childStyle = childStyle.merge (
520
521
TextStyle (backgroundColor: Colors .yellow, color: Colors .black));
521
522
break ;
523
+ case "sub" :
524
+ childStyle = childStyle.merge (
525
+ TextStyle (
526
+ fontSize: childStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR ,
527
+ ),
528
+ );
529
+ break ;
522
530
case "del" :
523
531
case "s" :
524
532
case "strike" :
@@ -730,6 +738,18 @@ class HtmlRichTextParser extends StatelessWidget {
730
738
case "img" :
731
739
if (showImages) {
732
740
if (node.attributes['src' ] != null ) {
741
+
742
+ final width = imageProperties? .width ??
743
+ ((node.attributes['width' ] != null )
744
+ ? double .tryParse (node.attributes['width' ])
745
+ : null
746
+ );
747
+ final height = imageProperties? .height ??
748
+ ((node.attributes['height' ] != null )
749
+ ? double .tryParse (node.attributes['height' ])
750
+ : null
751
+ );
752
+
733
753
if (node.attributes['src' ].startsWith ("data:image" ) &&
734
754
node.attributes['src' ].contains ("base64," )) {
735
755
precacheImage (
@@ -739,20 +759,14 @@ class HtmlRichTextParser extends StatelessWidget {
739
759
),
740
760
),
741
761
buildContext,
742
- onError: onImageError,
762
+ onError: onImageError ?? (_,__) {} ,
743
763
);
744
764
parseContext.rootWidgetList.add (GestureDetector (
745
765
child: Image .memory (
746
766
base64.decode (
747
767
node.attributes['src' ].split ("base64," )[1 ].trim ()),
748
- width: imageProperties? .width ??
749
- ((node.attributes['width' ] != null )
750
- ? double .tryParse (node.attributes['width' ])
751
- : null ),
752
- height: imageProperties? .height ??
753
- ((node.attributes['height' ] != null )
754
- ? double .tryParse (node.attributes['height' ])
755
- : null ),
768
+ width: (width ?? - 1 ) > 0 ? width: null ,
769
+ height: (height ?? - 1 ) > 0 ? width: null ,
756
770
scale: imageProperties? .scale ?? 1.0 ,
757
771
matchTextDirection:
758
772
imageProperties? .matchTextDirection ?? false ,
@@ -780,19 +794,30 @@ class HtmlRichTextParser extends StatelessWidget {
780
794
precacheImage (
781
795
NetworkImage (node.attributes['src' ]),
782
796
buildContext,
783
- onError: onImageError,
797
+ onError: onImageError ?? (_,__) {} ,
784
798
);
785
799
parseContext.rootWidgetList.add (GestureDetector (
786
800
child: Image .network (
787
801
node.attributes['src' ],
788
- width: imageProperties? .width ??
789
- ((node.attributes['width' ] != null )
790
- ? double .parse (node.attributes['width' ])
791
- : null ),
792
- height: imageProperties? .height ??
793
- ((node.attributes['height' ] != null )
794
- ? double .parse (node.attributes['height' ])
795
- : null ),
802
+ frameBuilder: (context, child, frame, _) {
803
+ if (node.attributes['alt' ] != null && frame == null ) {
804
+ return BlockText (
805
+ child: RichText (
806
+ textAlign: TextAlign .center,
807
+ text: TextSpan (
808
+ text: node.attributes['alt' ],
809
+ style: nextContext.childStyle,
810
+ ),
811
+ )
812
+ );
813
+ }
814
+ if (frame != null ) {
815
+ return child;
816
+ }
817
+ return Container ();
818
+ },
819
+ width: (width ?? - 1 ) > 0 ? width: null ,
820
+ height: (height ?? - 1 ) > 0 ? height: null ,
796
821
scale: imageProperties? .scale ?? 1.0 ,
797
822
matchTextDirection:
798
823
imageProperties? .matchTextDirection ?? false ,
@@ -817,20 +842,6 @@ class HtmlRichTextParser extends StatelessWidget {
817
842
},
818
843
));
819
844
}
820
- if (node.attributes['alt' ] != null ) {
821
- parseContext.rootWidgetList.add (BlockText (
822
- shrinkToFit: shrinkToFit,
823
- margin:
824
- EdgeInsets .symmetric (horizontal: 0.0 , vertical: 10.0 ),
825
- padding: EdgeInsets .all (0.0 ),
826
- child: RichText (
827
- textAlign: TextAlign .center,
828
- text: TextSpan (
829
- text: node.attributes['alt' ],
830
- style: nextContext.childStyle,
831
- children: < TextSpan > [],
832
- ))));
833
- }
834
845
}
835
846
}
836
847
break ;
@@ -955,39 +966,11 @@ class HtmlRichTextParser extends StatelessWidget {
955
966
}
956
967
}
957
968
958
- Paint _getPaint (Color color) {
959
- Paint paint = new Paint ();
960
- paint.color = color;
961
- return paint;
962
- }
963
-
964
969
String condenseHtmlWhitespace (String stringToTrim) {
965
970
stringToTrim = stringToTrim.replaceAll ("\n " , " " );
966
971
while (stringToTrim.indexOf (" " ) != - 1 ) {
967
972
stringToTrim = stringToTrim.replaceAll (" " , " " );
968
973
}
969
974
return stringToTrim;
970
975
}
971
-
972
- bool _isNotFirstBreakTag (dom.Node node) {
973
- int index = node.parentNode.nodes.indexOf (node);
974
- if (index == 0 ) {
975
- if (node.parentNode == null ) {
976
- return false ;
977
- }
978
- return _isNotFirstBreakTag (node.parentNode);
979
- } else if (node.parentNode.nodes[index - 1 ] is dom.Element ) {
980
- if ((node.parentNode.nodes[index - 1 ] as dom.Element ).localName == "br" ) {
981
- return true ;
982
- }
983
- return false ;
984
- } else if (node.parentNode.nodes[index - 1 ] is dom.Text ) {
985
- if ((node.parentNode.nodes[index - 1 ] as dom.Text ).text.trim () == "" ) {
986
- return _isNotFirstBreakTag (node.parentNode.nodes[index - 1 ]);
987
- } else {
988
- return false ;
989
- }
990
- }
991
- return false ;
992
- }
993
976
}
0 commit comments