skip to Main Content

I am using Flutter GoRouter to navigate from the Homespace with path / to a search page with path /search. I transition to the search page via context.go('/search').

From the search page when I swipe back, I get a weird animation albeit I am in the correct page.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I solved the issue by following this recipe on Github.


  2. As per my understanding of your query, you are getting some weird animation at the time of back press from the screen.

    Once, I had face same issue and have implemented custom page transition and in that I am passing the page as parameter.

    The code of custom transition page will be as mentioned bellow which will help you to remove that default weird looking navigation animation:

    route.dart // In my project, I have mentioned all route navigations in separate file.
    final _rootNavigatorKey = GlobalKey<NavigatorState>();
    
    final GoRouter goRouterProvider = GoRouter(
      navigatorKey: _rootNavigatorKey,
      routes: [
        GoRoute(
          path: AppRoutes.notifications, // Your search route as string will be here...
          parentNavigatorKey: _rootNavigatorKey,
          pageBuilder: (context, state) => customPageTransition<void>(
            context: context,
            state: state,
            child: const NotificationsScreen(), // Your SearchScreen will be here...
          ),
        ),
      ],
    );
    

    Here is the function ‘customPageTransition’ which works expected in my project.

    CustomTransitionPage customPageTransition<T>({
      required BuildContext context,
      required GoRouterState state,
      required Widget child,
    }) {
      return CustomTransitionPage<T>(
        key: state.pageKey,
        child: child,
        transitionsBuilder: (context, animation, secondaryAnimation, child) =>
            FadeTransition(opacity: animation, child: child),
      );
    }
    

    In case, you want to implement any specific transition, you can replace it instead of FadeTransition. you can also define multiple transition as per the requirement as I have did it for the specific use case.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search