Skip to Content
Routes & ModulesPage TransitionsOverview

Page Transitions

Page transitions in go_router_modular come from the go_transitions package, which is re-exported by go_router_modular. You don’t need an extra import — GoTransitions is available as soon as you import package:go_router_modular/go_router_modular.dart.

Three ways to apply a transition

1. Per route

Set transition (and optionally transitionDuration) directly on a ChildRoute:

lib/src/modules/home/home_module.dart
ChildRoute( '/details', child: (context, state) => const DetailsPage(), transition: GoTransitions.fade, transitionDuration: const Duration(milliseconds: 300), )

2. Global default

Set a default transition for every route in Modular.configure:

lib/main.dart
await Modular.configure( appModule: AppModule(), initialRoute: '/', defaultTransition: GoTransitions.fadeUpwards, defaultTransitionDuration: const Duration(milliseconds: 600), );

Any route that doesn’t declare its own transition falls back to this default.

3. Stateful shell branches

To animate switching between branches of a stateful shell route, pass a container builder from StatefulShellBranchTransitions:

lib/src/app_module.dart
StatefulShellModularRoute( builder: (context, state, navigationShell) => ScaffoldWithNavBar(navigationShell: navigationShell), navigatorContainerBuilder: StatefulShellBranchTransitions.withGoTransition( GoTransitions.scale.withRotation, transitionDuration: const Duration(milliseconds: 400), ), branches: [ // ... ], )

Inheritance

Routes inside a ModuleRoute inherit the parent’s transition unless they set their own. The resolution order for a given route is:

  1. The route’s own transition / transitionDuration.
  2. The transition inherited from its parent ModuleRoute.
  3. The global default from Modular.configure.

defaultTransitionDuration also sets GoTransition.defaultDuration, which is used by routes and stateful shells that don’t declare an explicit duration.

Common transitions

These are the transitions used throughout the example app:

TransitionEffect
GoTransitions.fadeSimple cross-fade
GoTransitions.fadeUpwardsFade while sliding up
GoTransitions.slide.toRight.withFadeSlide to the right combined with a fade
GoTransitions.slide.toLeft.withFadeSlide to the left combined with a fade
GoTransitions.scale.withRotationScale combined with rotation
GoTransitions.rotate.withScaleRotation combined with scale
GoTransitions.rotate.withScale.withFadeRotation + scale + fade
GoTransitions.themePlatform default (Material/Cupertino)

Next steps

Last updated on