Skip to content

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

Closed

Description

@Gorniaky

I'm developing an app, but I noticed that the dispose method of a widget is being called more than once, causing the second time to throw an error with the unregister method, which I think is unnecessary since it could easily be ignored.

Activity

  1. escamoteur commented on Jan 25, 2026

    @escamoteur
    Member
  2. Gorniaky commented on Jan 25, 2026

    @Gorniaky
    Author

    I understand there's something wrong with the flow, but in production this only hinders progress. I simply put the function in a try-catch block because, to me, there's nothing wrong with my workflow, mainly because I register the dependency in initState and cancel it in dispose.

    In short, my suggestion is to ignore the instance's non-existence.

    That would be a possibility but in reality this shows you that you call dispose once too often.

    If you cannot fix it add a guard value in your dispose function.
    It's important that the library throws so you know that there is a logic problem
    Am 25. Jan. 2026, 13:32 -0500 schrieb Gorniaky @.***>:
    …

    Gorniaky created an issue (flutter-it/get_it#420)
    I'm developing an app, but I noticed that the dispose method of a widget is being called more than once, causing the second time to throw an error with the unregister method, which I think is unnecessary since it could easily be ignored.
    —
    Reply to this email directly, view it on GitHub, or unsubscribe.
    You are receiving this because you are subscribed to this thread.Message ID: @.***>

  3. AzazelSensei commented on Aug 13, 2026

    @AzazelSensei

    Opened #424 — default still throws, optional ignoreIfNotRegistered if a second dispose should no-op.

  4. escamoteur commented on Sep 19, 2026

    @escamoteur
    Member

    Shipped in get_it 9.3.0 as a global flag: GetIt.I.skipUnregisterIfNotRegistered = true makes unregister a no-op for missing registrations (default still throws). See #424 for the reasoning behind the global flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions