GlobalScope
final userKey = ScopeKey<User>();
final user = validateLogin(username, password);
if (user != null) {
GlobalScope().value(userKey, user);
}final user = use(userKey);An improved singleton
void main() {
GlobalScope().value(userKey, user);
}
test('a unit test', () {
final user = use(userKey); // return user injected in main
Scope().
..value(userKey, testUser) // override the userKey
..run(() =>
{
final user = use(userKey); // returns testUser
});
// we are back outside the Scope.
final user = use(userKey); // return user injected in main
}Last updated