Skip to content

Image.asset() doesn't load/render image when descendant of disabled TickerMode widget. #118709

Description

@champeauxr

When an Image.asset() widget is a descendant of a TickerMode widget, the image will not load if the TickerMode widget's enabled property is set to false. Additionally, if the TickerMode widget is disabled after the image is loaded, then there is some weird behavior when the app is backgrounded and then brought back into the foreground. This foregrounding behavior is different between iOS and Android.

On iOS, if the TickerMode.enabled property is set to false after the image has loaded and then you background and foreground the app, the image will disappear. If the enabled property is then set to true, the image will reload. While the app is in the foreground and the image has been loaded, you can turn the enabled property on and off repeatedly without affecting the image. See the attached iOSBehavior.mp4 video for a demonstration.

On Android, if you set the enabled property to false, background the app, and then foreground it again, the image will still be visible. However, if you then set the enabled property to true, the image will flicker as it briefly disappears and reappears. Also, if the TickerMode.enabled property is true when the app is backgrounded and foregrounded, and then you set enabled to false, the image will disappear. Except for the first time after foregrounding, you can enable and disable the TickerMode widget without affecting the rendering of the image. See the attached AndroidBehavior.mp4 video for a demonstration.

Steps to Reproduce

An example app that demonstrates the problem can be found in this repository:

https://github.com/champeauxr/image_tickermode

The app has an Image.asset widget inside a TickerMode widget, along with a Switch widget (outside the TickerMode) that is used to enable/disable the TickerMode. The TickerMode is initially disabled.

For both iOS and Android:

  1. Launch the example app
  2. See that the image has not loaded.
  3. Turn on the Switch widget
  4. See that the image has loaded
  5. Repeatedly toggle the Switch widget
  6. See that the image remains visible.

For iOS behavior:
7. After the image is visible, turn the Switch widget off.
8. See that the image remains visible
9. Background and foreground the app
10. See that the image has disappeared
11. Turn the Switch widget on
12. See that the image has appeared.

For Android Behavior:
7. After the image is visible, turn the Switch widget off.
8. See that the image remains visible
9. Background and foreground the app
10. See that the image remains visible
11. Turn the Switch widget on.
12. See the image flicker as it briefly disappears and reappears.
13. With the Switch widget on, background and foreground the app
14. See that the image remains visible
15. Turn the Switch widget off
16. See that the image disappears

Code Example

The following is the app code contained in the example app. Reproducing the issue requires an image asset, so it is recommended to clone the following repository:

https://github.com/champeauxr/image_tickermode

The app has an Image.asset widget inside a TickerMode widget, along with a Switch widget (outside the TickerMode) that is used to enable/disable the TickerMode. The TickerMode is initially disabled.

import'package:flutter/material.dart';
voidmain() {
runApp(constMyApp());
}
classMyAppextendsStatelessWidget {
constMyApp({super.key});
// This widget is the root of your application.@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
title:'Flutter Demo',
theme:ThemeData(
primarySwatch:Colors.blue,
),
home:constMyHomePage(title:'Flutter Demo Home Page'),
);
}
}
classMyHomePageextendsStatefulWidget {
constMyHomePage({super.key, requiredthis.title});
finalString title;
@overrideState<MyHomePage> createState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> {
bool _tickerEnabled =false;
voidonTickerEnabledChanged(bool value) {
setState(() {
_tickerEnabled = value;
});
}
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(
title:Text(widget.title),
),
body:Center(
child:Column(
children: [
TickerMode(
enabled: _tickerEnabled,
child:Image.asset('assets/17644.png'),
),
constText('Image by rawpixel.com on Freepik.com'),
constSizedBox(height:32),
Row(
children: [
constText('Ticker Mode'),
Switch(value: _tickerEnabled, onChanged: onTickerEnabledChanged)
],
)
],
),
),
);
}
}
flutter analyze
flutter analyze
Analyzing image_tickermode... No issues found! (ran in 2.8s)
flutter doctor -v
flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.6.1 21G217 darwin-x64, locale en)
• Flutter version 3.3.10 on channel stable at /Users/richchampeaux/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 135454af32 (5 weeks ago), 2022-12-15 07:36:55 -0800
• Engine revision 3316dd8728
• Dart version 2.18.6
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at /Users/richchampeaux/Library/Android/sdk
• Platform android-33, build-tools 33.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.3)
• Android Studio at /Applications/Android Studio.app/Contents
• 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 11.0.13+0-b1751.21-8125866)
[✓] Connected device (4 available)
• Pixel 3a (mobile) • 941AY0HYEJ • android-arm64 • Android 12 (API 32)
• 160-TP iPhone 7 Plus (mobile) • ee2789b3974ca47255609a936e7172e58f01325b • ios • iOS 14.4.2 18D70
• macOS (desktop) • macos • darwin-x64 • macOS 12.6.1 21G217 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.87
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
iOSBehavior.mp4
AndroidBehavior.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: assetsPackaging, accessing, or using assetsa: imagesLoading, displaying, rendering imagesfound in release: 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework teamwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions