Prevent Initial Animation in Flutter Go Router (go_router)

274 views Asked by At

I have set up some routes with go_router inside a LayoutBuilder. This is so I can resize my app on desktop and change the UI depending on the space available.

Here's a simplified view of my app:

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {
        return Scaffold(
          body: Routes(),
        ),
      },
    );
  }
}

Then here are my routes:

class Routes extends StatelessWidget {
  Routes({super.key});

  final GoRouter router = GoRouter(
    navigatorKey: navigatorKey,
    initialLocation: '/',
    routes: [
      GoRoute(
        path: '/',
        builder: (BuildContext context, GoRouterState state) {
          return Scaffold(
            body: const Master(),
          );
        },
      ),
    ],
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: router,
    );
  }
}

The problem I'm having is that there is an initial animation for the router. When you hot restart or resize the window and trigger the LayoutBuilder, it rebuilds the Routes widget. This is fine, but the initial animation gets triggered multiple times and looks jarring. Here's a screen recording to show what I mean.

How do I disable this initial go_router animation so the app stays still while the window is being resized?

0

There are 0 answers