getUsername method

Future<String> getUsername(
  1. String pubkey
)

Return the username from a given pubkey.

Implementation

Future<String> getUsername(String pubkey) async {
  String username = '';

  final QueryOptions options = QueryOptions(
    document: gql(getIdQuery),
    variables: <String, dynamic>{
      'pubkey': pubkey,
    },
  );
  final QueryResult result = await _client.query(options);

  if (result.hasException) {
    printIfDebug(result.exception.toString());
    throw Exception('Unexpected error happened in graphql request');
  } else if (result.data?['idty']?['username'] != null) {
    username = result.data!['idty']['username'];
  }

  return username;
}