Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properties lost in Singleton binding defined on shared module #938

Open
agustin-garcia opened this issue Feb 21, 2024 · 1 comment
Open
Labels
new New issue request attention

Comments

@agustin-garcia
Copy link

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

@agustin-garcia agustin-garcia added the new New issue request attention label Feb 21, 2024
@edugemini
Copy link
Contributor

@agustin-garcia, do it:

return Modular.get<AuthenticationManager>().isLogged;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new New issue request attention
Projects
None yet
Development

No branches or pull requests

2 participants