Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
- Create an
AnimatedCrossFadewith differentdurationandreverseDurationattributes, and children with different dimensions - Switch its
crossFadeStatefromCrossFadeState.showSecondtoCrossFadeState.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
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
mernen commentedon May 29, 2023
While investigating this issue, I found something odd:
The
reverseDurationis passed on toAnimatedSizehere:flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart
Lines 379 to 385 in cab21c2
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 asAnimatedOpacityorAnimatedScale) has areverseDurationproperty.Going further, the
reverseDurationmanages to reach all the way intoRenderAnimatedSize’sAnimationController:flutter/packages/flutter/lib/src/rendering/animated_size.dart
Lines 87 to 91 in cab21c2
…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
AnimatedSizeandRenderAnimatedSize, andAnimatedCrossFadeshould take the responsibility of passingAnimatedSizethe appropriate duration.huycozy commentedon May 29, 2023
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
firstChildfromsecondChild(withshowFirst), the width of the blue Container quickly shrinks to the target size. Is the issue there?mernen commentedon May 29, 2023
The
durationis set to 1 second, andreverseDurationis set to 5 seconds. The size transition (on the black border) is always 1 second long, though, i.e. it's always usingduration, and neverreverseDuration.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.
mernen commentedon May 29, 2023
@huycozy I've updated the linked DartPad, the video, and the explanation of what to observe. Hopefully this will make things clearer.
huycozy commentedon May 30, 2023
Thank you for updating the sample, it's more evident than previous one. Reproduced this issue on the latest
stableandmasterchannels.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!Use reverseDuration for the AnimatedCrossFade size animation (flutter…