Comments (2)
ModalRoute
builds a _ModalScope
which builds a ListenableBuilder
which calls buildTransitions
.
child: ListenableBuilder(
listenable: _listenable, // immutable
builder: (BuildContext context, Widget? child) {
return widget.route.buildTransitions(
context,
widget.route.animation!,
widget.route.secondaryAnimation!,
ListenableBuilder
listens to a merger of animation
and secondaryAnimation
.
final List<Listenable> animations = <Listenable>[
if (widget.route.animation != null) widget.route.animation!,
if (widget.route.secondaryAnimation != null) widget.route.secondaryAnimation!,
];
_listenable = Listenable.merge(animations);
This means ListenableBuilder
calls buildTransitions
on every frame of the transition.
The documentation says buildTransitions
is called "each time the Route's state changes while it is visible" but does not mention that it is called unconditionally for every transition frame.
/// The [buildTransitions] method, in contrast to [buildPage], is called each
/// time the [Route]'s state changes while it is visible (e.g. if the value of
/// [canPop] changes on the active route).
It also does not mention the performance implications of using buildTransitions
over buildPage
when it recommends that users place their transition widgets there.
The Material widget layer follows this recommendation when it ties MaterialPageRoute
into the app theme via MaterialRouteTransitionMixin
.
@override
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
final PageTransitionsTheme theme = Theme.of(context).pageTransitionsTheme;
return theme.buildTransitions<T>(this, context, animation, secondaryAnimation, child);
}
In doing so, it causes every page transition in a MaterialApp
to incur the additional cost of Theme.of(context)
every frame.
Hash table lookups and widget builds are cheap, but is there a reason for the framework to incur these costs? Especially during a transition when it must produce frames as quickly as possible?
If there is a reason, perhaps the framework could document this behavior and recommend to developers that they place their transition widgets in buildPage
whenever those widgets will not change for the duration of the transition.
On the other hand, could this behavior be a bug?
from flutter.
Thanks for the report. Reproduced the same result as above.
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.22.1, on macOS 14.1 23B74 darwin-x64, locale en-VN)
• Flutter version 3.22.1 on channel stable at /Users/huynq/Documents/GitHub/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision a14f74ff3a (11 hours ago), 2024-05-22 11:08:21 -0500
• Engine revision 55eae6864b
• Dart version 3.4.1
• DevTools version 2.34.3
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-34, build-tools 34.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.9+0-17.0.9b1087.7-11185874)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
• Xcode at /Applications/Xcode15.3.app/Contents/Developer
• Build 15E204a
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.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
• android-studio-dir = /Applications/Android Studio.app/
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (version 1.89.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.88.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 125.0.6422.76
[✓] Network resources
• All expected network resources are available.
• No issues found!
[!] Flutter (Channel master, 3.22.0-44.0.pre.10, on macOS 14.1 23B74 darwin-x64, locale en-VN)
• Flutter version 3.22.0-44.0.pre.10 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 fe0932f2c0 (76 minutes ago), 2024-05-22 22:19:25 -0400
• Engine revision b8b82454e3
• Dart version 3.5.0 (build 3.5.0-178.0.dev)
• DevTools version 2.36.0-dev.10
• 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 34.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-34, build-tools 34.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.9+0-17.0.9b1087.7-11185874)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
• Xcode at /Applications/Xcode15.3.app/Contents/Developer
• Build 15E204a
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.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
• android-studio-dir = /Applications/Android Studio.app/
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (version 1.89.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.88.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 125.0.6422.76
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.
from flutter.
Related Issues (20)
- [two_dimensional_scrollables] TapGestureRecognizer of TableSpan not working after setState() HOT 8
- [Impeller] Latest Vulkan SDK introduces validation failures.
- List/Detail template crashes on horizontal orientation of foldable android emulators HOT 2
- SliverAppBar should allow for a custom scroll physics or some control over collapse/expand speed, or should at least give an option to mirror native iOS behavior HOT 3
- please add menu mode to FilterChip HOT 1
- Add display dpi information to MediaQuery to calculate display size HOT 7
- adb devices does find my phone.flutter devices does not find my phone. HOT 2
- 3.22.1 does not support win7 HOT 2
- How do I use the same name and Bundle ID for my iOS and MacOS app? Can anyone help? HOT 1
- Failed to launches my Flutter WASM compiled web app (WebAssembly.compileStreaming() Compiling function failed HOT 4
- Keyboard Flickering Issue on Android Devices HOT 2
- Building Android always leaves a java process running. HOT 3
- [iOS Crash] Exiting from iOS multitasking UI may cause crash due to exit. HOT 9
- App hanging for at least 2000 ms - Issue only in production environment, unable to replicate HOT 2
- availableCameras HOT 2
- [go_router] Unwanted rerender with go_router when using push HOT 3
- Flutter arch document HOT 2
- Go Router test with StatefulShellRoute mock throws type error: The following _TypeError was thrown building KeyedSubtree-[GlobalKey#3ccf0]: type 'Null' is not a subtype of type 'StatefulElement' HOT 2
- Animation memory leak on some platforms HOT 1
- [Impeller] Bold is slightly less bold than Skia for certain fonts
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter.