Skip to content

Scope race conditions #316

Closed
Closed
@subzero911

Description

@subzero911

I pop scope on widget dispose and register a new singleton on a new screen open.
But the new singleton gets into the old scope which would got disposed in a next frame. That's because of screens transitions which has not finished, thus old screen's dispose function has called a bit later than new screen's initState.
I couldn't figure out for a long time why my new singleton disappears!

Proposal:

GetIt.pushNewScope() and GetIt.popScope() shouldn't be imperative.
Force user to register singletons inside of pushNewScope callback

var profileScope = GetIt.pushNewScope(init: (getIt) { 
  getIt.registerSingleton(EditProfileController());
}) 

GetIt.I.registerSingleton(YetAnotherController()); // does not get into the scope above

User should pop scope only by name or by instance:

  profileScope.pop();
  // or
  GetIt.popScope(profileScope);
  // or
  GetIt.popScope(name: 'profile');

also related issues #313, #303

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