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

why is languagestore, themestore, userstore registered in service_locator #126

Open
dyardy opened this issue May 11, 2022 · 2 comments
Open

Comments

@dyardy
Copy link

dyardy commented May 11, 2022

I notice in feature/mvi branch (the latest) that languagestore, themestore, userstore is registered in service_locator AS well as new'd up again in MyApp. This seems like duplication

i.e.
getIt.registerSingleton(LanguageStore(getIt()));
getIt.registerSingleton(ThemeStore(getIt()));
getIt.registerSingleton(UserStore(getIt()));

and also in my_app.dart
final ThemeStore _themeStore = ThemeStore(getIt());
final PostStore _postStore = PostStore(getIt());
final LanguageStore _languageStore = LanguageStore(getIt());
final UserStore _userStore = UserStore(getIt());

@tribal2
Copy link

tribal2 commented Jun 2, 2022

I notice the same because the UserStore builder was being called twice. I changed my code to:

-  final ThemeStore _themeStore = ThemeStore(getIt<Repository>());
-  final PostStore _postStore = PostStore(getIt<Repository>());
-  final LanguageStore _languageStore = LanguageStore(getIt<Repository>());
-  final UserStore _userStore = UserStore(getIt<UserRepository>());

+  final ThemeStore _themeStore = getIt<ThemeStore>();
+  final PostStore _postStore = getIt<PostStore>();
+  final LanguageStore _languageStore = getIt<LanguageStore>();
+  final UserStore _userStore = getIt<UserStore>();

I'm still learning Dart so I don't know if this was made on purpose or if this is a bug 🤷‍♂️

@v1pz3n
Copy link

v1pz3n commented Jan 28, 2023

@tribal2 thanks buddy! I think it's a bug as it double-initializes the store.
I applied your suggestion and it solved the problem of values saved in shared preferences when starting the application.

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

No branches or pull requests

3 participants