I am using GoRouter for navigation and GetX for multiple things, including updating the app's locale.
It is updating the language perfectly fine, but the problem is that somehow my navigation stack is getting reset after the call.
I've made a Screenvideo for a better understanding but you can also test it yourself here.
I update my locale by simply calling:
Locale locale = Locale(languageCode);
await Get.updateLocale(locale);
And my routing looks like this:
final rootNavigatorKey = GlobalKey<NavigatorState>();
class AppRouter {
static final _shellNavigatorKey = GlobalKey<NavigatorState>();
static final router = GoRouter(
initialLocation: IntroView.path,
debugLogDiagnostics: true,
navigatorKey: rootNavigatorKey,
routes: [
ShellRoute(
navigatorKey: _shellNavigatorKey,
pageBuilder: (context, state, child) {
return NoTransitionPage(
child: ScaffoldView(
child: child,
),
);
},
routes: [
GoRoute(
name: ProjectsView.name,
path: '/projects',
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) {
return const FadePageTransition(
page: ProjectsView(),
);
},
routes: [
GoRoute(
parentNavigatorKey: rootNavigatorKey,
path: ':projectTitle',
pageBuilder: (context, state) {
return FadePageTransition(
page: ProjectDetailScaffold(
project: Projects.values.byName(
state.params['projectTitle']!,
),
),
);
},
),
],
),
I am already passing the router as instance and I am using GetMaterialApp.router:
class App extends StatelessWidget {
final GoRouter router;
const App({
super.key,
required this.router,
});
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
...
],
child: GetMaterialApp.router(
routeInformationProvider: router.routeInformationProvider,
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
translationsKeys: translationsKeys,
locale: const Locale(LocaleConfiguration.baseLanguageCode),
fallbackLocale: const Locale(LocaleConfiguration.baseLanguageCode),
),
);
}
}
What am I missing here?
Let me know if you need any more info!