You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just put my hands on the library and it is really nice! But I can't find a example of how to work with scopes. The documentation shows no example and in my testes they simply doesn't work like navigators (as mentioned on the readme).
Can someone provide a simple, clean and straightforward piece of code? I am sure this will help others lost as am I.
EDIT: here is my test code:
final getit =GetIt.asNewInstance();
voidmain(List<String> arguments) async {
getit.pushNewScope(scopeName:'cli1');
getit.registerSingleton<ClientDatabase>(ClientDatabaseImpl(1));
printClient(); //Prints Client 1
getit.pushNewScope(scopeName:'cli2');
getit.registerSingleton<ClientDatabase>(ClientDatabaseImpl(2));
printClient(); //Prints Client 2
getit.popScope(); //Popping to cli1printClient(); //Still prints Client 2, but should be printing Client 1 since I've popped!
}
voidprintClient() =>print(getit.get<ClientDatabase>().getCliente()?.toString());
classClient {
int id;
Client(this.id);
@overrideStringtoString() =>'Client $id';
}
abstractclassClientDatabase {
ClientgetCliente();
}
classClientDatabaseImplextendsClientDatabase {
finalint id;
ClientDatabaseImpl(this.id);
@overrideClientgetCliente() =>Client(id);
}
The text was updated successfully, but these errors were encountered:
Seems that my problem was that popScope() runs async way, so It needs to awaited. After that, the code above will work!
Definetly a simple sample on the README file will be helpful for future users.
I agree, that part is a bit tricky. Little tip, often its helpful to take a look into the tests for a feature.
If you want to add a small example to the readme, I'm happy to get a PR ;-)
Uh oh!
There was an error while loading. Please reload this page.
I just put my hands on the library and it is really nice! But I can't find a example of how to work with scopes. The documentation shows no example and in my testes they simply doesn't work like navigators (as mentioned on the readme).
Can someone provide a simple, clean and straightforward piece of code? I am sure this will help others lost as am I.
EDIT: here is my test code:
The text was updated successfully, but these errors were encountered: