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

BindNotFoundException thrown after trying to access a disposed cubit initialized with i.addLazySingleton #923

Open
carloshpb opened this issue Dec 14, 2023 · 3 comments
Labels
new New issue request attention

Comments

@carloshpb
Copy link

carloshpb commented Dec 14, 2023

Describe the bug
I went to a screen to change the current sub-account to another sub-account. To make it simpler to handle the logic of calling the new data on this sub-account, I've disposed the cubits which contains the data and immediately moved to the home screen that uses the disposed cubit.

Every cubit of the app is initialized inside the modules of imports :

class AppModule extends Module {
  @override
  List<Module> get imports => [
    CoreModule(),
    ...
  ]
  ...
}

All of them were initialized with i.addLazySingleton.

When I move to another screen which also uses a cubit that was disposed, I get the :

BindNotFoundException: UnregisteredInstance: SubScreenCubit unregistered

Still, the page ends up loading the cubit and working normally. Everything works normally and the application doesn't crash at all, but this BindNotFoundException is always being thrown and, sadly, it is being added to the Crashlytics.

That's all I can say about the bug. Sadly I can't show the code as its proprietary.

Environment
Add your flutter doctor -v

Flutter 3.10.6
Dart 3.0.6
DevTools 2.23.1

Simulator OS versions:
iOS 17
Android 12

Currently running on a macOS 14.1.2

Add your pubspec.yaml
flutter_modular: ^6.3.2

To Reproduce
Dispose a cubit that is lazySingleton and call it again. The error doesn't show on console at all. But its caught on crashlytics.

Expected behavior
It is not supposed to throw BindNotFoundException, as the cubit was initialized again due to being a i.addLazySingleton.

@carloshpb carloshpb added the new New issue request attention label Dec 14, 2023
@jamesldr
Copy link

Do you really need it to be a singleton? From your description since you're disposing it, I think adding it as a factory would work better.

@caio-deiro
Copy link

I had the same Issue, @carloshpb do you find a solution for this problem?

@carloshpb
Copy link
Author

@caio-deiro I changed some codes... For example, I did more modules for inner children that are inside the parent module, which activate this bug. For now, doing this has solved my current situation. But the bug is still there. And it's weird, as it wasn't supposed to happen like this. But I also suspect the RouterOutlet may be the culprit as the Home module that I use to deal with the children makes use of a bottom navigation.

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

3 participants