Skip to content

FadeInImage works unexpectedly #94540

@werainkhatri

Description

@werainkhatri

When changing the image while the app is running, FadeInImage seems to work unexpectedly.

Steps to Reproduce:
Run the sample code (tested on Android and Linux, master and stable branches).

  1. A blue box appears, shortly later, it fades out and image 1 (mountains) fades in.
  2. Click on the image. Image 1 disappears, nothing appears for a while. Then the blue box appears and quickly fades out, fading in image 2 (bird).
  3. Click again. Image 2 disappears, and then (same as 2) occurs, fading in image 1.
  4. Click again. Image 2 appears immediately.
  5. Click again. (Same as 1) occurs.
  6. Click again. (Same as 4) occurs.
    And then it loops between them.

Expected behavior:

  1. Expected.
  2. The blue box should be shown as a placeholder instead of nothing.
  3. Since image 1 is cached now, there should not be any loading, it should appear immediately. But looking at the download speed in the top bar, it can be seen that image 1 is getting downloaded every time (same on Linux).
  4. Expected
  5. Same as 3
  6. Expected

Video on OnePlus 7T running Android 11. Tested on Linux (details in flutter doctor) and got the same results.

21-12-02-23-45-23.mp4
sample code
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool img = false;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        setState(() {
          img = !img;
        });
      },
      child: FadeInImage(
        placeholder: Image.network(
          'http://jacksonmetalroof.com/wp-content/uploads/2016/06/metal-roofing-color-gallery-blue-180x180.png',
        ).image,
        image: Image.network(
          img
              ? 'https://wallup.net/wp-content/uploads/2019/09/07/762373-postcard-paper-poster-advertising-vintage-retro-antique-christmas.jpg'
              : 'https://wallup.net/wp-content/uploads/2019/05/10/1003575-usa-parks-scenery-mountains-forests-california-clouds-kings-canyon-national-park-nature-wallpapers.jpg',
        ).image,
      ),
    );
  }
}
flutter doctor
[✓] Flutter (Channel stable, 2.5.0, on Pop!_OS 20.04 LTS 5.13.0-7620-generic,
    locale en_US.UTF-8)
    • Flutter version 2.5.0 at /home/werain/soft/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4cc385b4b8 (3 months ago), 2021-09-07 23:01:49 -0700
    • Engine revision f0826da7ef
    • Dart version 2.14.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /home/werain/Android/Sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /snap/android-studio/current/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

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

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.1
    • pkg-config version 0.29.1

[✓] Android Studio (version 2020.3)
    • Android Studio at /snap/android-studio/115/android-studio
    • Flutter plugin version 62.0.1
    • Dart plugin version 203.8452
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] Android Studio
    • Android Studio at /snap/android-studio/current/android-studio
    • 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
    • android-studio-dir = /snap/android-studio/current/android-studio
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension version 3.29.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Pop!_OS 20.04 LTS 5.13.0-7620-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 96.0.4664.45

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowfound in release: 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6found in release: 2.8Found to occur in 2.8frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions