diff --git a/lib/image_render.dart b/lib/image_render.dart index cb9d0e5ab4..234b63b598 100644 --- a/lib/image_render.dart +++ b/lib/image_render.dart @@ -225,13 +225,25 @@ double? _width(Map attributes) { return widthString == null ? widthString as double? : double.tryParse(widthString); } -double _aspectRatio(Map attributes, AsyncSnapshot calculated) { +double _aspectRatio( + Map attributes, + AsyncSnapshot calculated, +) { + double aspectRatio; final heightString = attributes["height"]; final widthString = attributes["width"]; if (heightString != null && widthString != null) { final height = double.tryParse(heightString); final width = double.tryParse(widthString); - return height == null || width == null ? calculated.data!.aspectRatio : width / height; + aspectRatio = height == null || width == null + ? calculated.data!.aspectRatio + : width / height; + } else { + aspectRatio = calculated.data!.aspectRatio; + } + if (!aspectRatio.isNaN) { + return aspectRatio; + } else { + return 1; } - return calculated.data!.aspectRatio; }