Skip to content

Unable to unregister a factory #131

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

Closed
naamapps opened this issue Nov 26, 2020 · 1 comment
Closed

Unable to unregister a factory #131

naamapps opened this issue Nov 26, 2020 · 1 comment

Comments

@naamapps
Copy link

Hey,
In the documentation it says:

If you need to you can also unregister your registered singletons and factories and pass a optional disposingFunction for clean-up.

However, when calling unregister with a factory instance, I get this error:

The following StateError was thrown while finalizing the widget tree:
Bad state: This instance of the type "SomeFactory" is not available in GetIt If you have registered
it as LazySingleton, are you sure you have used it at least once?

I am trying to unregister the factory to dispose some variables when exiting a page.
I am calling it in the dispose function.

  @override
  void dispose() {;
    locator.unregister(
      instance: SomeFactory,
      disposingFunction: SomeFactory.dispose,
    );
    super.dispose();
  }

Thanks for your help

@escamoteur
Copy link
Collaborator

As a Factory creates a new instance on every call you can't use the instance to unregister.
You have to unregister it with the same Type and (name if you used one) as when you registered.
Maybe have also a look at the new Scope functions in V5,perhaps they can make your live easier

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

2 participants