1
1
import 'dart:convert' ;
2
-
2
+ import 'image_properties.dart' ;
3
3
import 'package:flutter/gestures.dart' ;
4
4
import 'package:flutter/material.dart' ;
5
5
import 'package:html/dom.dart' as dom;
@@ -12,7 +12,7 @@ typedef CustomTextStyle = TextStyle Function(
12
12
);
13
13
typedef CustomEdgeInsets = EdgeInsets Function (dom.Node node);
14
14
typedef OnLinkTap = void Function (String url);
15
-
15
+ typedef OnImageTap = void Function ();
16
16
const OFFSET_TAGS_FONT_SIZE_FACTOR =
17
17
0.7 ; //The ratio of the parent font for each of the offset tags: sup or sub
18
18
@@ -157,6 +157,8 @@ class HtmlRichTextParser extends StatelessWidget {
157
157
color: Colors .blueAccent,
158
158
decorationColor: Colors .blueAccent,
159
159
),
160
+ this .imageProperties,
161
+ this .onImageTap,
160
162
});
161
163
162
164
final double indentSize = 10.0 ;
@@ -169,6 +171,8 @@ class HtmlRichTextParser extends StatelessWidget {
169
171
final CustomEdgeInsets customEdgeInsets;
170
172
final ImageErrorListener onImageError;
171
173
final TextStyle linkStyle;
174
+ final ImageProperties imageProperties;
175
+ final OnImageTap onImageTap;
172
176
173
177
// style elements set a default style
174
178
// for all child nodes
@@ -654,26 +658,65 @@ class HtmlRichTextParser extends StatelessWidget {
654
658
buildContext,
655
659
onError: onImageError,
656
660
);
657
- parseContext.rootWidgetList.add (Image .memory (base64.decode (
658
- node.attributes['src' ].split ("base64," )[1 ].trim ())));
661
+ parseContext.rootWidgetList.add (InkWell (
662
+ child: Image .memory (
663
+ base64.decode (node.attributes['src' ].split ("base64," )[1 ].trim ()),
664
+ width: imageProperties? .width,
665
+ height: imageProperties? .height,
666
+ scale: imageProperties? .scale ?? 1.0 ,
667
+ matchTextDirection: imageProperties? .matchTextDirection ?? false ,
668
+ centerSlice: imageProperties? .centerSlice,
669
+ gaplessPlayback: imageProperties? .gaplessPlayback ?? false ,
670
+ filterQuality: imageProperties? .filterQuality ?? FilterQuality .low,
671
+ alignment: imageProperties? .alignment ?? Alignment .center,
672
+ colorBlendMode: imageProperties? .colorBlendMode,
673
+ fit: imageProperties? .fit,
674
+ color: imageProperties? .color,
675
+ repeat: imageProperties? .repeat ?? ImageRepeat .noRepeat,
676
+ semanticLabel: imageProperties? .semanticLabel,
677
+ excludeFromSemantics: (imageProperties? .semanticLabel == null ) ? true : false ,
678
+ ),
679
+ onTap: onImageTap,
680
+ ));
659
681
} else {
660
682
precacheImage (
661
683
NetworkImage (node.attributes['src' ]),
662
684
buildContext,
663
685
onError: onImageError,
664
686
);
665
- parseContext.rootWidgetList
666
- .add (Image .network (node.attributes['src' ]));
687
+ parseContext.rootWidgetList.add (InkWell (
688
+ child: Image .network (
689
+ node.attributes['src' ],
690
+ width: imageProperties? .width,
691
+ height: imageProperties? .height,
692
+ scale: imageProperties? .scale ?? 1.0 ,
693
+ matchTextDirection: imageProperties? .matchTextDirection ?? false ,
694
+ centerSlice: imageProperties? .centerSlice,
695
+ gaplessPlayback: imageProperties? .gaplessPlayback ?? false ,
696
+ filterQuality: imageProperties? .filterQuality ?? FilterQuality .low,
697
+ alignment: imageProperties? .alignment ?? Alignment .center,
698
+ colorBlendMode: imageProperties? .colorBlendMode,
699
+ fit: imageProperties? .fit,
700
+ color: imageProperties? .color,
701
+ repeat: imageProperties? .repeat ?? ImageRepeat .noRepeat,
702
+ semanticLabel: imageProperties? .semanticLabel,
703
+ excludeFromSemantics: (imageProperties? .semanticLabel == null ) ? true : false ,
704
+ ),
705
+ onTap: onImageTap,
706
+ ));
707
+ }
708
+ if (node.attributes['alt' ] != null ) {
709
+ parseContext.rootWidgetList.add (BlockText (
710
+ margin: EdgeInsets .symmetric (horizontal: 0.0 , vertical: 10.0 ),
711
+ padding: EdgeInsets .all (0.0 ),
712
+ child: RichText (
713
+ textAlign: TextAlign .center,
714
+ text: TextSpan (
715
+ text: node.attributes['alt' ],
716
+ style: nextContext.childStyle,
717
+ children: < TextSpan > [],
718
+ ))));
667
719
}
668
- } else if (node.attributes['alt' ] != null ) {
669
- parseContext.rootWidgetList.add (BlockText (
670
- margin: EdgeInsets .symmetric (horizontal: 0.0 , vertical: 10.0 ),
671
- padding: EdgeInsets .all (0.0 ),
672
- child: RichText (
673
- text: TextSpan (
674
- text: node.attributes['alt' ],
675
- children: < TextSpan > [],
676
- ))));
677
720
}
678
721
break ;
679
722
case "li" :
0 commit comments