Add `tokenOrNull` util function

This commit is contained in:
krawieck 2020-09-15 15:21:06 +02:00
parent fb8f6bfaa5
commit 08c80b2568
1 changed files with 18 additions and 0 deletions

View File

@ -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);
}