1

我在 Flutter 应用程序中使用@protocol,想知道是否有办法在尝试与其共享密钥之前验证是否存在另一个@sign。现在我创建了一个函数,它将尝试与指定的@sign 共享一个密钥。如果有AtLookUpException,我认为用户不存在:

 /// Check if user exists in this namespace by trying to share a key with them
  Future<bool> checkForUser(String atSign) async {
    /// Do test send to see if @ sign exists
    AtKey testKey = AtKey();
    testKey.key = 'test';

    testKey.sharedWith = atSign;

    try {
      await atProtocolService.atClientImpl.put(testKey, 'Are you there?');
      return true;
    } on AtLookUpException catch (e){
      print('AtLookUpException: '+ e.errorMessage);
      return false;
    }

}

为了进一步验证,您可以检查 AtLookUpException 的错误消息,如下所示:

未找到辅助服务器:未找到 atsign 的辅助 url:@bob

这是最好或最快的方法吗?

4

1 回答 1

1

有一个可供您使用的库:

https://github.com/atsign-foundation/at_libraries/tree/master/at_server_status

随意调整代码的任何部分,以适应您的用例。

一如既往,欢迎您的反馈。

于 2021-04-05T21:16:19.530 回答