You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm defining a shared/code module by creating a Singleton binding but its properties become null when I call a child Module
In the initial (Login) module I can do:
Modular.get().isLogged = true;
print("isLogged: ${Modular.get().isLogged}");
and everything seems all right.
But as soon as I navigate to the HOME (or any other) module from the LOGIN module via the "Modular.to.pushReplacementNamed(AppPaths.home);" instruction, the AuthenticationManager properties become NULL again
Could you please look at the code snippet and try to find out what am I missing?
Thanks
class CoreModule extends Module { @OverRide
List get binds => [Bind.singleton((i) => AuthenticationManager(), export: true),];
}
class AppModule extends Module { @OverRide
List get imports => [CoreModule()]; @OverRide
List get routes => [
ChildRoute('/', child: (_, __) => const AppRoot(), guards: [AuthGuard()]),
ModuleRoute(AppPaths.home, module: HomeModule()),
ModuleRoute(AppPaths.login, module: LoginModule()),
];
}
class LoginModule extends Module { @OverRide
List get imports => [CoreModule()]; @OverRide
List get routes => [ChildRoute('/', child: (_, __) => LoginWidget()),];
}
class HomeModule extends Module { @OverRide
List get imports => [CoreModule()]; @OverRide
List get routes => [ChildRoute('/', child: (_, __) => const HomePage()),];
}
I'm defining a shared/code module by creating a Singleton binding but its properties become null when I call a child Module
In the initial (Login) module I can do:
Modular.get().isLogged = true;
print("isLogged: ${Modular.get().isLogged}");
and everything seems all right.
But as soon as I navigate to the HOME (or any other) module from the LOGIN module via the "Modular.to.pushReplacementNamed(AppPaths.home);" instruction, the AuthenticationManager properties become NULL again
Could you please look at the code snippet and try to find out what am I missing?
Thanks
class CoreModule extends Module {
@OverRide
List get binds => [Bind.singleton((i) => AuthenticationManager(), export: true),];
}
class AppModule extends Module {
@OverRide
List get imports => [CoreModule()];
@OverRide
List get routes => [
ChildRoute('/', child: (_, __) => const AppRoot(), guards: [AuthGuard()]),
ModuleRoute(AppPaths.home, module: HomeModule()),
ModuleRoute(AppPaths.login, module: LoginModule()),
];
}
class LoginModule extends Module {
@OverRide
List get imports => [CoreModule()];
@OverRide
List get routes => [ChildRoute('/', child: (_, __) => LoginWidget()),];
}
class HomeModule extends Module {
@OverRide
List get imports => [CoreModule()];
@OverRide
List get routes => [ChildRoute('/', child: (_, __) => const HomePage()),];
}
class AuthGuard extends RouteGuard {AuthGuard() : super(redirectTo: AppPaths.login);
@OverRide
Future canActivate(String url, ModularRoute router) async {
return Modular.get().isLogged;
}
}
FLUTTER
• flutter_modular 5.0.3
• Flutter version 3.19.0 on channel stable
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision bae5e49bc2 (6 days ago), 2024-02-13 17:46:18 -0800
• Engine revision 04817c99c9
• Dart version 3.3.0
• DevTools version 2.31.1
The text was updated successfully, but these errors were encountered: