Skip to content

fix: aspect ratio should never be NaN. #769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/image_render.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,25 @@ double? _width(Map<String, String> attributes) {
return widthString == null ? widthString as double? : double.tryParse(widthString);
}

double _aspectRatio(Map<String, String> attributes, AsyncSnapshot<Size> calculated) {
double _aspectRatio(
Map<String, String> attributes,
AsyncSnapshot<Size> 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you solution is okay but would it have been enough to just check that height is not 0 and return 1 in that case?

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;
}