context.push() using go_router doesn't work

285 Views Asked by At

I have a screen called /login who has a button and i want to push to another one called /login/main but doesn't work, did i do something wrong in the router config?

Actually i have debug logs enable and says: [GoRouter] pushing /login/main but dont doesn't push

Screen:

class _LoginScreenState extends State<LoginScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          const Spacer(),
          SizedBox(
            width: MediaQuery.of(context).size.width * 0.9,
            child: ElevatedButton(
              onPressed: () {
                context.push('/login/main');
              },
              child: const Text('Iniciar sesión'),
            ),
          ),
        ],
      ),
    );
  }
}

go_router:

final goRouterProvider = Provider<GoRouter>((ref) {
  return GoRouter(
    navigatorKey: _rootNavigatorKey,
    debugLogDiagnostics: true,
    routes: [
      ShellRoute(
        navigatorKey: _shellNavigatorKey,
        builder: (context, state, child) {
          return AppScaffold(child: child);
        },
        routes: [
          GoRoute(
            path: '/index',
            name: 'Index',
            builder: (context, state) => IndexHome(
              key: state.pageKey,
            ),
          ),
          GoRoute(
            path: '/profile',
            name: 'Profile',
            builder: (context, state) => ProfileScreen(
              key: state.pageKey,
            ),
          ),
        ],
      ),
      GoRoute(
        parentNavigatorKey: _rootNavigatorKey,
        path: '/login', //THIS THE ACTUAL SCREEN
        name: 'Login',
        builder: (context, state) => LoginScreen(
          key: state.pageKey,
        ),
        routes: [
          GoRoute(
            path: 'main', //THIS IS THE ROUTE I WANT TO PUSH
            name: 'LoginMain',
            builder: (context, state) => LoginMainScreen(
              key: state.pageKey,
            ),
          ),
        ],
      ),
    ],
  );
});

0

There are 0 best solutions below