0

I was trying to run flutter web sample with go_router package using navigator 2 flow. I wanted to achieve something like, on press of a button current route should be replaced by new route and on back press of a chrome browser it should go to respective screen. For ex: My first screen is home screen with url like website.com/home. After that on tap of a button I move to new screen which is view contact with url like website.com/home/view-contact. Now on tap of one button my current route view contact should be replaced by new screen route like edit contact with url like website.com/home/edit-contact. But, now when I try to go back then it is still showing the home/view-contact view.

My code for replace route is like, But it's not working

context.replace(
                                        '${AppRouter.pathHome}/${AppRouter.pathEditContact}',
                                        extra: arguments);

Following is my go_router routes.

static final List<GoRoute> _appRoutes = [
    GoRoute(
        path: AppRouter.pathLogin,
        builder: (BuildContext context, GoRouterState state) =>
            const LoginScreen()),
    GoRoute(
      path: AppRouter.pathHome,
      builder: (BuildContext context, GoRouterState state) =>
          const HomeScreen(),
      routes: [
        GoRoute(
            path: AppRouter.pathCreateContact,
            builder: (BuildContext context, GoRouterState state) =>
                const CreateContactScreen()),
        GoRoute(
            path: AppRouter.pathReviewDetails,
            builder: (BuildContext context, GoRouterState state) =>
                ReviewDetailsScreen(docId: state.extra as String)),
        GoRoute(
            path: AppRouter.pathViewContact,
            builder: (BuildContext context, GoRouterState state) =>
                ViewContactScreen(docId: state.extra as String)),
        GoRoute(
            path: AppRouter.pathEditContact,
            builder: (BuildContext context, GoRouterState state) =>
                EditContactScreen(
                    editContactItem: state.extra as EditContactArguments)),
      ],
    ),
  ];

Let me know if anyone has the solution for it.

Thanks.

Jay Mungara
  • 6,663
  • 2
  • 27
  • 49

0 Answers0