Refactor to use `watch` instead of `select` and add check if instance is added
This commit is contained in:
parent
6310ed988b
commit
b329a5fe4e
|
@ -7,12 +7,11 @@ import '../stores/accounts_store.dart';
|
|||
/// or null if this instance is not added or doesn't
|
||||
/// have any user logged in
|
||||
String tokenOrNull(BuildContext context, String instanceUrl) {
|
||||
if (context
|
||||
// ignore: avoid_types_on_closure_parameters
|
||||
.select((AccountsStore store) => store.isAnonymousFor(instanceUrl))) {
|
||||
final store = context.watch<AccountsStore>();
|
||||
|
||||
if (!store.users.containsKey(instanceUrl) ||
|
||||
store.isAnonymousFor(instanceUrl)) {
|
||||
return null;
|
||||
}
|
||||
return context
|
||||
// ignore: avoid_types_on_closure_parameters
|
||||
.select((AccountsStore store) => store.defaultTokenFor(instanceUrl).raw);
|
||||
return store.defaultTokenFor(instanceUrl).raw;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue