Add `tokenOrNull` util function
This commit is contained in:
parent
fb8f6bfaa5
commit
08c80b2568
|
@ -0,0 +1,18 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../stores/accounts_store.dart';
|
||||
|
||||
/// returns either raw token for default user of `instanceUrl`
|
||||
/// 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))) {
|
||||
return null;
|
||||
}
|
||||
return context
|
||||
// ignore: avoid_types_on_closure_parameters
|
||||
.select((AccountsStore store) => store.defaultTokenFor(instanceUrl).raw);
|
||||
}
|
Loading…
Reference in New Issue