Skip to content

Hero animation bug in Flutter 3.7 - widget is rendered both in flight and at target (duplicated) #121325

@mikeesouth

Description

@mikeesouth

Steps to Reproduce

This problem occurred when upgrading from flutter stable 3.3.10 to 3.7.0 and it still persists in flutter 3.7.5. This is reproducible on iOS, Android and Windows, not sure about Mac, Linux and Impeller. This bug does not seem to happen in flutter web - not with html and not with canvaskit.

There may be more cases where this bug exists but I can reproduce it when navigating between two screens and the second screen has a FutureBuilder. When this FutureBuilder renders some kind of loading / waiting state, then the Hero chain is broken so we will not see a hero transition - that's fine. But when we're popping the route and returning to the first screen, the hero animation can be displayed and so it does - except that the widget is rendered both in flight and already at the target position so the hero widget is seen twice. This did not happen in flutter 3.3.10 and it looks weird.

flutter_hero_future_builder.mp4

I have also added a button called Future Builder (completed) and this shows a FutureBuilder where the Future already has a value when rendering the first time. The future builder still starts with "snapshot.hasData = false" so it displays the loading animation for 1 frame and this breaks the hero chain. It would be nice if the FutureBuilder would directly get it's data if the future is completed - that would make future builders more viable so that we can use them in cases where we sometimes need to wait for futures but if the future is already completed, it would just render the child without triggering the loading state of the future builder. Maybe that's a separate feature request but I still wanted to mention it here :)

  1. Execute flutter run on the code sample

Expected results: That the Hero animation transitions back when popping the screen from Future Builder screens.

Actual results: That the Hero widget is displayed both at the target position AND also rendering as a transition towards the target position. The same widget is duplicated during the hero transition.

Code sample

flutter_hero_future_builder

Logs

Flutter logs not attached, no relevant information in them.

Flutter analyze:

Analyzing flutter_hero_future_builder...
No issues found! (ran in 1.4s)

Flutter doctor:

[√] Flutter (Channel stable, 3.7.5, on Microsoft Windows [Version 10.0.22000.1574], locale en-SE)
    • Flutter version 3.7.5 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c07f788888 (11 hours ago), 2023-02-22 17:52:33 -0600
    • Engine revision 0f359063c4
    • Dart version 2.19.2
    • DevTools version 2.20.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\micke\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Professional 2022 17.4.5)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Professional
    • Visual Studio Professional 2022 version 17.4.33403.182
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2021.2)
    • Android Studio at C:\Program Files\Android\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
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)

[√] VS Code, 64-bit edition (version 1.75.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.58.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22000.1574]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 110.0.5481.177
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 110.0.1587.49

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: animationAnimation APIsc: regressionIt was better in the past than it is nowf: material designflutter/packages/flutter/material repository.f: routesNavigator, Router, and related APIs.found in release: 3.7Found to occur in 3.7found in release: 3.8Found to occur in 3.8frameworkflutter/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 team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions