Skip to content

Commit 20dfaa4

Browse files
committed
Potentially resolve #485
1 parent b785705 commit 20dfaa4

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

example/lib/generated_plugin_registrant.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
// ignore_for_file: lines_longer_than_80_chars
66

7-
import 'package:url_launcher_web/url_launcher_web.dart';
87
import 'package:video_player_web/video_player_web.dart';
98
import 'package:wakelock_web/wakelock_web.dart';
109

1110
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
1211

1312
// ignore: public_member_api_docs
1413
void registerPlugins(Registrar registrar) {
15-
UrlLauncherPlugin.registerWith(registrar);
1614
VideoPlayerPlugin.registerWith(registrar);
1715
WakelockWeb.registerWith(registrar);
1816
registrar.registerMessageHandler();

lib/image_render.dart

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'dart:convert';
44
import 'package:flutter/material.dart';
55
import 'package:flutter_html/html_parser.dart';
66
import 'package:flutter_svg/flutter_svg.dart';
7+
import 'package:flutter_svg/parser.dart';
78
import 'package:html/dom.dart' as dom;
89

910
typedef 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

Comments
 (0)