Skip to content

AnimatedCrossFade size transition does not respect reverseDuration #127780

Closed

Description

@mernen

Is there an existing issue for this?

Steps to reproduce

  1. Create an AnimatedCrossFade with different duration and reverseDuration attributes, and children with different dimensions
  2. Switch its crossFadeState from CrossFadeState.showSecond to CrossFadeState.showFirst

Expected results

The size transition should be as long as the opacity transition (i.e. it should be the same as reverseDuration, since this is a transition from the second state to the first).

Actual results

The opacity transition correctly follows reverseDuration, but the size transition always follows duration instead.

Code sample

DartPad demo

Press "Animate forward", and then "Animate backwards". Notice that the fade transition respects reverseDuration and occurs slowly over 2 seconds, but the black border always changes size very quickly, because it always follows duration.

Screenshots or Video

Screenshots / Video demonstration
AnimatedCrossFade.demo.mov

A screen capture from the provided demo. Notice that when going forward the size and content transitions have the same duration, but when going backwards the content transition is (correctly) slow, while the size transition is as fast as it was when going forward.

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.1, on macOS 13.4 22F66 darwin-arm64, locale en-BR)
    • Flutter version 3.10.1 on channel stable at /Users/daniel/Library/Flutter/fvm/versions/3.10.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d3d8effc68 (12 days ago), 2023-05-16 17:59:05 -0700
    • Engine revision b4fb11214d
    • Dart version 3.0.1
    • DevTools version 2.23.1

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/daniel/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Users/daniel/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.10121639/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 17.0.6+0-17.0.6b802.4-9586694)

[✓] Android Studio (version 2022.2)
    • Android Studio at /Users/daniel/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841/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 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.78.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.64.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.4 22F66 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 112.0.5615.137

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

! Doctor found issues in 1 category.

Activity

  1. mernen commented on May 29, 2023

    @mernen
    ContributorAuthor

    While investigating this issue, I found something odd:

    The reverseDuration is passed on to AnimatedSize here:

    child: AnimatedSize(
    alignment: widget.alignment,
    duration: widget.duration,
    reverseDuration: widget.reverseDuration,
    curve: widget.sizeCurve,
    child: widget.layoutBuilder(topChild, topKey, bottomChild, bottomKey),
    ),

    But that doesn’t make much sense — AnimatedSize, being an implicitly animated widget, doesn’t have a concept of going forwards or backwards. Indeed, as far as I know, no other implicitly-animated widget (such as AnimatedOpacity or AnimatedScale) has a reverseDuration property.

    Going further, the reverseDuration manages to reach all the way into RenderAnimatedSize’s AnimationController:

    _controller = AnimationController(
    vsync: vsync,
    duration: duration,
    reverseDuration: reverseDuration,
    )..addListener(() {

    …but, as far as I can tell, this is never used, since this controller only goes forward().

    So it seems to me that this property should be deprecated and eventually removed from AnimatedSize and RenderAnimatedSize, and AnimatedCrossFade should take the responsibility of passing AnimatedSize the appropriate duration.

  2. added
    in triagePresently being triaged by the triage team
    on May 29, 2023
  3. huycozy commented on May 29, 2023

    @huycozy
    Member

    Hi @mernen
    I'm not sure I'm seeing this clearly, but I'm seeing the same duration between the size transition going forward and back. The only difference that can be clear to see is that when returning to firstChild from secondChild (with showFirst), the width of the blue Container quickly shrinks to the target size. Is the issue there?

  4. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on May 29, 2023
  5. mernen commented on May 29, 2023

    @mernen
    ContributorAuthor

    The duration is set to 1 second, and reverseDuration is set to 5 seconds. The size transition (on the black border) is always 1 second long, though, i.e. it's always using duration, and never reverseDuration.

    The size clipping looks bad but it's entirely unrelated — I apologize for the confusion this causes. I'll adjust the demo later so we have a clearer illustration.

  6. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on May 29, 2023
  7. mernen commented on May 29, 2023

    @mernen
    ContributorAuthor

    @huycozy I've updated the linked DartPad, the video, and the explanation of what to observe. Hopefully this will make things clearer.

  8. huycozy commented on May 30, 2023

    @huycozy
    Member

    Thank you for updating the sample, it's more evident than previous one. Reproduced this issue on the latest stable and master channels.

    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.10.2, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
        • Flutter version 3.10.2 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 9cd3d0d9ff (22 hours ago), 2023-05-23 20:57:28 -0700
        • Engine revision 90fa3ae28f
        • Dart version 3.0.2
        • DevTools version 2.23.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 32.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E222b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • 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 17.0.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.78.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.64.0
    
    [✓] Connected device (3 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
        • macOS (desktop)  • macos            • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
        • Chrome (web)     • chrome           • web-javascript • Google Chrome 113.0.5672.126
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    [!] Flutter (Channel master, 3.11.0-14.0.pre.73, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
        • Flutter version 3.11.0-14.0.pre.73 on channel master at /Users/huynq/Documents/GitHub/flutter_master
        ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 59128bd61e (49 minutes ago), 2023-05-29 22:35:15 -0400
        • Engine revision 93a8d41549
        • Dart version 3.1.0 (build 3.1.0-155.0.dev)
        • DevTools version 2.23.1
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 32.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E222b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • 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 17.0.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.78.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.64.0
    
    [✓] Connected device (3 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
        • macOS (desktop)  • macos            • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
        • Chrome (web)     • chrome           • web-javascript • Google Chrome 113.0.5672.126
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
  9. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on May 30, 2023
  10. added
    P2Important issues not at the top of the work list
    on Jun 6, 2023
  11. added a commit that references this issue on Nov 6, 2026
    eea8e06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: animationAnimation APIsfound in release: 3.10Found to occur in 3.10found in release: 3.11Found to occur in 3.11frameworkflutter/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