Skip to content

Image.network Widget with cacheWidth/cacheHeight smaller than the image displays black #158093

Description

@michaelheider

Steps to reproduce

  1. Build app for web.
  2. Access with a web browser.

If cacheWidth = cacheHeight = 30 (which is smaller than the 40px image size), the page will display a black square of the correct size instead of the image.

If cacheWidth = cacheHeight = 50 (which is larger or equal than the 40px image size), the page will display the image correctly. it also works if both are null.

Pitfalls avoided: Make sure the image you use for testing exists (i.e. you can open it in your browser). Ensure the image has permissive CORS headers (no CORS errors in browser console).

Expected results

The image displays properly no matter the values of cacheWidth and cacheHeight.

Actual results

If cacheWidth or cacheHeight are smaller than the image's pixel dimensions, then the image does not display, an all-black placeholder of the correct size is displayed instead.

No error messages or special logs.

Code sample

Code sample
import 'package:flutter/widgets.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Image.network(
      cacheWidth: 30,
      cacheHeight: 30,
      'https://fastly.picsum.photos/id/505/40/40.jpg?hmac=egB4BZLkmlPCkk32_xTVvQg2I8QZH2w369evjD3Q1Pk',
    );
  }
}

Flutter Doctor output

Doctor output
[✓] Flutter (Channel beta, 3.27.0-0.1.pre, on Ubuntu 22.04.5 LTS 6.8.0-48-generic, locale en_US.UTF-8)
    • Flutter version 3.27.0-0.1.pre on channel beta at /home/michael/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2e2c358c9b (13 days ago), 2024-10-22 11:02:13 -0400
    • Engine revision af0f0d559c
    • Dart version 3.6.0 (build 3.6.0-334.3.beta)
    • DevTools version 2.40.1

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /home/michael/Android/Sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /home/michael/Android/Sdk
    • Java binary at: /snap/android-studio/161/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✗] Linux toolchain - develop for Linux desktop
    ✗ clang++ is required for Linux development.
      It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/
    ✗ CMake is required for Linux development.
      It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
    ✗ ninja is required for Linux development.
      It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from
      https://github.com/ninja-build/ninja/releases
    ✗ pkg-config is required for Linux development.
      It is likely available from your distribution (e.g.: apt install pkg-config), or can be downloaded from
      https://www.freedesktop.org/wiki/Software/pkg-config/

[✓] Android Studio (version 2024.1)
    • Android Studio at /snap/android-studio/161
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)

[✓] VS Code (version 1.95.1)
    • VS Code at /snap/code/current/usr/share/code
    • Flutter extension version 3.100.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.5 LTS 6.8.0-48-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 130.0.6723.91

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: imagesLoading, displaying, rendering imagesc: regressionIt was better in the past than it is nowfound in release: 3.27Found to occur in 3.27has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions