flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

CachedNetworkImageProvider does not work together with ResizeImage and ResizeImagePolicy.fit

Open Hannnes1 opened this issue 2 years ago • 1 comments

🐛 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:

Imgur

Expected behavior

It should look like NetworkImage:

Imgur

Reproduction steps

  • Create a new Flutter project
  • Replace the content of main.dart with:
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

Hannnes1 avatar Jun 07 '23 14:06 Hannnes1

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.

Hannnes1 avatar Jun 07 '23 14:06 Hannnes1