CachedNetworkImageProvider does not work together with ResizeImage and ResizeImagePolicy.fit
🐛 Bug Report
Flutter recently added a policy parameter to ResizeImage, where one of the enum values is ResizeImagePolicy.fit. Basically, it is used to be able to resize an image while retaining the aspect ratio (See here for more context: https://github.com/flutter/flutter/issues/118543). This does not work together with CachedNetworkImageProvider. The image will be squished to fit into the width and height no matter the value of width and height. See below:

Expected behavior
It should look like NetworkImage:

Reproduction steps
- Create a new Flutter project
- Replace the content of
main.dartwith:
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
color: Colors.red,
width: 300,
height: 300,
child: const Image(
image: ResizeImage(
CachedNetworkImageProvider('https://placekitten.com/500/1000'),
width: 300,
height: 300,
policy: ResizeImagePolicy.fit,
),
),
),
),
);
}
}
- See squished cat
Configuration
Version: 3.2.3 Flutter version: 3.10.2
Platform:
- [ ] :iphone: iOS
- [x] :robot: Android
Also, CachedNetworkImage should add expose the new policy of ResizeImage for use together with memCacheWidth and memCacheHeight. Not sure if that should be a separate issue or not.