@@ -1263,8 +1263,7 @@ class ResizeImage extends ImageProvider<ResizeImageKey> {
12631263 /// defined by `width` and `height` . The image will lose detail and
12641264 /// use less memory if resized to a size smaller than the native size.
12651265 ///
1266- /// At least one of `width` and `height` must be non-null. If they are
1267- /// non-null, they must be greater than zero.
1266+ /// At least one of `width` and `height` must be non-null.
12681267 ///
12691268 /// {@macro flutter.painting.ResizeImage.useLogicalSize}
12701269 const ResizeImage (
@@ -1274,9 +1273,7 @@ class ResizeImage extends ImageProvider<ResizeImageKey> {
12741273 this .policy = ResizeImagePolicy .exact,
12751274 this .allowUpscaling = false ,
12761275 this .useLogicalSize = false ,
1277- }) : assert (width != null || height != null ),
1278- assert (width == null || width > 0 ),
1279- assert (height == null || height > 0 );
1276+ }) : assert (width != null || height != null );
12801277
12811278 /// The [ImageProvider] that this class wraps.
12821279 final ImageProvider imageProvider;
@@ -1415,6 +1412,8 @@ class ResizeImage extends ImageProvider<ResizeImageKey> {
14151412
14161413 return ui.TargetImageSize (width: targetWidth, height: targetHeight);
14171414 case ResizeImagePolicy .fit:
1415+ // A very thin image can derive a side of 0, which cannot be decoded.
1416+ // Clamp only the derived sides, so that a given side of 0 still fails.
14181417 final double aspectRatio = intrinsicWidth / intrinsicHeight;
14191418 final int maxWidth = effectiveWidth ?? intrinsicWidth;
14201419 final int maxHeight = effectiveHeight ?? intrinsicHeight;
@@ -1423,36 +1422,31 @@ class ResizeImage extends ImageProvider<ResizeImageKey> {
14231422
14241423 if (targetWidth > maxWidth) {
14251424 targetWidth = maxWidth;
1426- targetHeight = targetWidth ~ / aspectRatio;
1425+ targetHeight = math. max ( 1 , targetWidth ~ / aspectRatio) ;
14271426 }
14281427
14291428 if (targetHeight > maxHeight) {
14301429 targetHeight = maxHeight;
1431- targetWidth = ( targetHeight * aspectRatio).floor ();
1430+ targetWidth = math. max ( 1 , ( targetHeight * aspectRatio).floor () );
14321431 }
14331432
14341433 if (allowUpscaling) {
14351434 if (effectiveWidth == null ) {
14361435 assert (effectiveHeight != null );
14371436 targetHeight = effectiveHeight! ;
1438- targetWidth = ( targetHeight * aspectRatio).floor ();
1437+ targetWidth = math. max ( 1 , ( targetHeight * aspectRatio).floor () );
14391438 } else if (effectiveHeight == null ) {
14401439 targetWidth = effectiveWidth;
1441- targetHeight = targetWidth ~ / aspectRatio;
1440+ targetHeight = math. max ( 1 , targetWidth ~ / aspectRatio) ;
14421441 } else {
1443- final int derivedMaxWidth = ( maxHeight * aspectRatio).floor ();
1444- final int derivedMaxHeight = maxWidth ~ / aspectRatio;
1442+ final int derivedMaxWidth = math. max ( 1 , ( maxHeight * aspectRatio).floor () );
1443+ final int derivedMaxHeight = math. max ( 1 , maxWidth ~ / aspectRatio) ;
14451444 targetWidth = math.min (maxWidth, derivedMaxWidth);
14461445 targetHeight = math.min (maxHeight, derivedMaxHeight);
14471446 }
14481447 }
14491448
1450- // A very thin image can derive a side of 0, which cannot be decoded.
1451- // The given sides are greater than 0, so this changes only derived sides.
1452- return ui.TargetImageSize (
1453- width: math.max (1 , targetWidth),
1454- height: math.max (1 , targetHeight),
1455- );
1449+ return ui.TargetImageSize (width: targetWidth, height: targetHeight);
14561450 }
14571451 },
14581452 );
0 commit comments