@@ -4,6 +4,7 @@ import 'dart:convert';
44import 'package:flutter/material.dart' ;
55import 'package:flutter_html/html_parser.dart' ;
66import 'package:flutter_svg/flutter_svg.dart' ;
7+ import 'package:flutter_svg/parser.dart' ;
78import 'package:html/dom.dart' as dom;
89
910typedef ImageSourceMatcher = bool Function (
@@ -140,18 +141,21 @@ ImageRender networkImageRender({
140141 future: completer.future,
141142 builder: (BuildContext buildContext, AsyncSnapshot <Size > snapshot) {
142143 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+ ),
155159 );
156160 } else if (snapshot.hasError) {
157161 return altWidget? .call (_alt (attributes)) ??
@@ -211,3 +215,14 @@ double? _width(Map<String, String> attributes) {
211215 final widthString = attributes["width" ];
212216 return widthString == null ? widthString as double ? : double .tryParse (widthString);
213217}
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