New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There should be no default page transitions for desktop and web platforms. #99052
Comments
Right now users can use a custom Page object that disables the transition, but requires some custom code to switch based on the platform. Also, there needs to be a 1ms delay when this is used with go_router. Instead, does it make sense to define a new PageTransitionsBuilder? class NoAnimationPageTransitionsBuilder extends PageTransitionsBuilder {
const NoAnimationPageTransitionsBuilder();
@override
Widget buildTransitions<T>(
PageRoute<T> route,
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child,
) {
return child;
}
}
And then use that as the default for linux, macOS, and Windows in the static const Map<TargetPlatform, PageTransitionsBuilder> _defaultBuilders = <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.linux: FadeUpwardsPageTransitionsBuilder(), // Should be NoAnimationPageTransitionsBuilder?
TargetPlatform.macOS: CupertinoPageTransitionsBuilder(), // Should be NoAnimationPageTransitionsBuilder?
TargetPlatform.windows: FadeUpwardsPageTransitionsBuilder(), // Should be NoAnimationPageTransitionsBuilder?
}; Am I understanding correctly that the only other thing that's needed is a way to customize the transition duration based on the platform? |
Also, #95764 seems related |
Does this also looks related? - #41564 |
Yes, that was my initial thought as well. I think likely the same fix would solve both of these. Basically, the solution would be that the If no one is currently working this, I can try to figure that out 👍🏻
Yup I think the same fix can probably encapsulate this one as well. |
I think this could be considered a bug with higher priority than P5 rather than a feature request, because clients are having to work around this issue currently to meet user expectations. Also, we're looking at changing the default behavior which could be surprising / disruptive to some apps, and so the sooner we do it, the less apps will be disrupted. See internal Google document https://docs.google.com/document/d/1MPf4N81YWppEgEN8dqwwhTwTBliV_T0jCbbdaSdefaQ/edit#bookmark=id.qsc6q9wh6nxu for more context. |
I agree with @jacobsimionato this should be higher priority, for those coming across this issue here is a workaround: class NoPageTransitionsBuilder extends PageTransitionsBuilder {
const NoPageTransitionsBuilder();
@override
Widget buildTransitions<T>(
PageRoute<T>? route,
BuildContext? context,
Animation<double> animation,
Animation<double>? secondaryAnimation,
Widget child,
) {
return child;
}
} And then in pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.linux: NoPageTransitionsBuilder(),
TargetPlatform.macOS: NoPageTransitionsBuilder(),
TargetPlatform.windows: NoPageTransitionsBuilder(),
},
), |
@jacobsimionato I'm getting an access denied error when trying to read the internal Google document you linked. If possible, can you share with at least read access? Looks very interesting and relevant to something I'm working on at the moment. |
Hi rydmike, I'm sorry I can't share that internal doc. My apologies for linking to an inaccessible doc here! It doesn't say much more than what is already on this issue though - I think its important that Flutter has sensible defaults for each platform, including the newer ones, and that these are based on end user expectations. |
Am I correct in saying there is no way to change default page transition durations? The workaround @tmpfs posted doesn't remove the secondaryAnimation duration, so it fixes navigating to a page but not back. The only way to make web routing behave correctly is to wrap every individual route in a If the only workaround requires extra code on every route, I would agree it seems worth fixing |
Example: Using @tmpfs example yields a back delay: with_delay.movOnly possible to remove by wrapping in without_delay.movSo we actually shouldn't even touch |
@benhawkinsicon , yes that is annoying, there are other issues about the delay problem: I really wish this was fixed properly in the Flutter framework but for now all I have is this workaround. |
+1 I'm 2 days into building my first app in flutter and I was immediately confused by why my large web pages routes were awkwardly animating. To make things worse (i.e. more complex..), I want to make my app adaptive. In the adaptive paradigm, I would argue that:
The above workaround (thanks @tmpfs ! I'll use this pattern until something better presents) seems to be platform specific (i.e. blanket case for all web screens) and doesn't cover my use-case, which I suspect would be a common one. Following 👀 |
@darrenaustin is there an idea of when this might land please? I find this delay on back navigation personally very frustrating as I navigate the app (300ms is very noticeable) and I am sure my users will find the delay perplexing. If there is something I can do to help move this forward please let me know. |
This can be worked around by specifying
@override
Page<void> buildPage(BuildContext context, GoRouterState state) =>
CustomTransitionPage(
child: const FooScreen(),
key: state.pageKey,
transitionDuration: Duration.zero,
reverseTransitionDuration: Duration.zero,
transitionsBuilder: (_, __, ___, child) => child,
); more practical example: @immutable
class HomeRoute extends GoRouteData {
const HomeRoute();
@override
Page<void> buildPage(BuildContext context, GoRouterState state) =>
_NoTransition(state, child: const HomeScreen());
}
class _NoTransition extends CustomTransitionPage {
_NoTransition(GoRouterState state, {required super.child})
: super(
key: state.pageKey,
transitionsBuilder: (_, __, ___, child) => child,
reverseTransitionDuration: Duration.zero,
transitionDuration: Duration.zero,
);
}
|
@eEQK , this isn't working for me. I added this to a class _NoTransition extends CustomTransitionPage {
_NoTransition(GoRouterState state, {required super.child})
: super(
key: state.pageKey,
transitionsBuilder: (_, __, ___, child) => child,
reverseTransitionDuration: Duration.zero,
transitionDuration: Duration.zero,
);
}
// Standard page builder.
Page<dynamic> pageBuilder(
BuildContext context, GoRouterState state, Widget child) {
if (isDesktop()) {
return _NoTransition(state, child: child);
}
return MaterialPage(child: child);
} Then I assign the Edit: apparently assigning to the Page<dynamic> noTransitionPageBuilder(Widget child) {
if (isDesktop()) {
return NoTransitionPage(child: child);
}
return MaterialPage(child: child);
} The |
Not sure how I can help you @tmpfs since I created a minimal example and it works: |
As page transitions are not common on desktop and web applications, the default transitions on these platforms should be removed.
An attempt at this was tried with #82596, but it had an issue with the delay was still occurring even though the transition gone.
The text was updated successfully, but these errors were encountered: