Skip to content

Add optional ignoreIfNotRegistered to unregister #420 - #424

Closed
AzazelSensei wants to merge 1 commit into
flutter-it:mainfrom
AzazelSensei:feat/unregister-ignore-if-not-registered
Closed

AzazelSensei wants to merge 1 commit into
flutter-it:mainfrom
AzazelSensei:feat/unregister-ignore-if-not-registered

Conversation

@AzazelSensei

Copy link
Copy Markdown

Widget dispose can run twice. unregister still throws by default so that still shows a double-dispose, but you can pass ignoreIfNotRegistered: true if the second call should just no-op.

getIt.unregister<MyService>(ignoreIfNotRegistered: true);

Fixes #420

Default still throws when the type or instance is missing.
Pass ignoreIfNotRegistered: true if a second dispose should no-op.
@AzazelSensei

Copy link
Copy Markdown
Author

This has been ignored long enough. Closing. Maybe put a note on the README if PRs aren't welcome.

escamoteur added a commit that referenced this pull request Sep 19, 2026
- skipUnregisterIfNotRegistered: global flag mirroring skipDoubleRegistration (#420, #424)
- ObjectRegistration.acceptsParams; passing params to a registration without
  a param factory now fails an assert instead of being ignored
- CONTRIBUTING.md adapted from #426; ship only get-it-expert skill; untrack pubspec.lock
@escamoteur

Copy link
Copy Markdown
Member

You were right to be annoyed, sorry — the repo simply wasn't looked after for a while, which is not how PRs should be treated.

We went with a slightly different shape in 9.3.0: a global flag GetIt.I.skipUnregisterIfNotRegistered = true, mirroring the existing skipDoubleRegistration, instead of a per-call parameter. Reasoning: if a double unregister is fine in one place it's really a global decision ("I don't want get_it to police this"); per-call opt-outs tend to hide real logic bugs. Credited you and @Gorniaky in the changelog. Thanks for pushing this.

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

Successfully merging this pull request may close these issues.

Make the unregister method ignore the non-existence of an instance instead of throwing an error.

2 participants