@@ -4,6 +4,7 @@ import 'dart:convert';
4
4
import 'package:flutter/material.dart' ;
5
5
import 'package:flutter_html/html_parser.dart' ;
6
6
import 'package:flutter_svg/flutter_svg.dart' ;
7
+ import 'package:flutter_svg/parser.dart' ;
7
8
import 'package:html/dom.dart' as dom;
8
9
9
10
typedef ImageSourceMatcher = bool Function (
@@ -140,18 +141,21 @@ ImageRender networkImageRender({
140
141
future: completer.future,
141
142
builder: (BuildContext buildContext, AsyncSnapshot <Size > snapshot) {
142
143
if (snapshot.hasData) {
143
- return Image .network (
144
- src,
145
- headers: headers,
146
- width: width ?? _width (attributes) ?? snapshot.data! .width,
147
- height: height ?? _height (attributes),
148
- frameBuilder: (ctx, child, frame, _) {
149
- if (frame == null ) {
150
- return altWidget? .call (_alt (attributes)) ??
151
- Text (_alt (attributes) ?? "" , style: context.style.generateTextStyle ());
152
- }
153
- return child;
154
- },
144
+ return AspectRatio (
145
+ aspectRatio: _aspectRatio (attributes, snapshot),
146
+ child: Image .network (
147
+ src,
148
+ headers: headers,
149
+ width: width ?? _width (attributes) ?? snapshot.data! .width,
150
+ height: height ?? _height (attributes),
151
+ frameBuilder: (ctx, child, frame, _) {
152
+ if (frame == null ) {
153
+ return altWidget? .call (_alt (attributes)) ??
154
+ Text (_alt (attributes) ?? "" , style: context.style.generateTextStyle ());
155
+ }
156
+ return child;
157
+ },
158
+ ),
155
159
);
156
160
} else if (snapshot.hasError) {
157
161
return altWidget? .call (_alt (attributes)) ??
@@ -211,3 +215,14 @@ double? _width(Map<String, String> attributes) {
211
215
final widthString = attributes["width" ];
212
216
return widthString == null ? widthString as double ? : double .tryParse (widthString);
213
217
}
218
+
219
+ double _aspectRatio (Map <String , String > attributes, AsyncSnapshot <Size > calculated) {
220
+ final heightString = attributes["height" ];
221
+ final widthString = attributes["width" ];
222
+ if (heightString != null && widthString != null ) {
223
+ final height = double .tryParse (heightString);
224
+ final width = double .tryParse (widthString);
225
+ return height == null || width == null ? calculated.data! .aspectRatio : width / height;
226
+ }
227
+ return calculated.data! .aspectRatio;
228
+ }
0 commit comments