Add custom page transitions with GoRouter

Flutter tips Published on

Page transitions are a key part of making your app feel smooth and easy to use. They guide the user between screens and make navigation feel natural.

Why Page Transitions Matter

Smooth animations when moving from one page to another can really improve how people feel about your app. It makes the app feel more polished and professional.

Create Your Own Transition Helper

You can define a simple function that builds a custom transition for you. This uses CustomTransitionPage and a transition like FadeThroughTransition (or any other you prefer).

Example Transition Helper

Here's how a simple helper function might look to define a custom page transition:

Page<dynamic> buildPageTransition(
  BuildContext context, 
  GoRouterState state,
  Widget child,
) => CustomTransitionPage<dynamic>(
  key: state.pageKey,
  child: child,
  transitionsBuilder: (context, animation, secondaryAnimation, child) =>
    FadeThroughTransition(
      animation: animation,
      secondaryAnimation: secondaryAnimation,
      child: child,
    ),
);

You can build your own animations or use ones available from packages on pub.dev.

Using the Transition in Your Route

Once you have your helper function, you use it within your GoRouter route definition. Instead of just providing the builder for the page, you use pageBuilder and call your transition helper function.

Example Route Definition

Here's how you use the pageBuilder with your custom transition helper:

GoRoute(
  path: '/signin',
  builder: (context, state) => const SignInPage(),
  pageBuilder: (context, state) => buildPageTransition(context, state, const SignInPage()),
),

Customize Default Transitions

You can also set default page transitions for your whole app directly in your theme settings. This allows you to apply specific transitions based on the platform (like Android or iOS).

Example Theme Customization

pageTransitionsTheme: PageTransitionsTheme(
  builders: {
    TargetPlatform.android: const ZoomPageTransitionsBuilder(),
    TargetPlatform.iOS: const CupertinoPageTransitionsBuilder(),
  },
),

Save 3 months of work

Create your app using our 6 years of making Flutter apps and more than 50+ apps

kickstarter for flutter apps

Frequently Asked Questions

Why are page transitions important in an app?

Page transitions help improve the user experience by making navigation between screens feel smooth and intuitive. They make the app feel more polished.

How do I add a custom transition with GoRouter?

You can define a helper function using `CustomTransitionPage` and your desired animation, then use this helper function in the `pageBuilder` property of your GoRoute.

Can I use transitions from packages?

Yes, you can use transition animations provided by packages available on pub.dev within your `transitionsBuilder`.

How do I set a default transition for my whole app?

You can customize the default page transitions for different platforms by setting the `pageTransitionsTheme` property in your app's theme.

Can I create my own page transition animation?

Yes, Flutter allows you to create completely custom transition animations if the built-in ones or package options don't meet your needs.

Read more
You may also be interested in
Android adb cheat sheet  blog card image
Android adb cheat sheet
Published on 2025-05-12T12:24:44.312Z
Avoid testing using mocks  blog card image
Avoid testing using mocks
Published on 2025-05-19T07:10:51.218Z
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved