Skip to content

Commit

Permalink
Fix zero size image (#1266)
Browse files Browse the repository at this point in the history
Related to #1260
  • Loading branch information
daohoangson authored Jun 9, 2024
1 parent 8d413e8 commit 339c5a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core/lib/src/widgets/css_sizing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,11 @@ class _RenderCssSizing extends RenderProxyBox {
final sizeWidth = scopedChild.getDryLayout(tightWidth);

final childAspectRatio = sizeWidth.width / sizeWidth.height;
final sizeHeightRatio = sizeHeight.width / sizeHeight.height;
const epsilon = 0.01;
if ((childAspectRatio - sizeHeight.width / sizeHeight.height).abs() >
epsilon) {
if (childAspectRatio.isNaN ||
sizeHeightRatio.isNaN ||
(childAspectRatio - sizeHeightRatio).abs() > epsilon) {
return null;
}

Expand Down
10 changes: 10 additions & 0 deletions packages/core/test/tag_img_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ void main() {
});

group('error handing', () {
testWidgets('renders zero dimensions', (WidgetTester tester) async {
// https://github.com/daohoangson/flutter_widget_from_html/issues/1260
const html = '<img src="${helper.kDataUri}" width="0" height="0" />';
final explained = await helper.explain(tester, html);
expect(
explained,
contains('[CssSizing:height≥0.0,height=0.0,width≥0.0,width=0.0,child='),
);
});

testWidgets('executes errorBuilder', (WidgetTester tester) async {
const html = 'Foo <img src="data:image/jpg;base64,xxxx" /> bar';
await tester.pumpWidget(
Expand Down

1 comment on commit 339c5a5

@github-actions
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.