getAuthRequired method Null safety

Future<AuthRequiredResponse> getAuthRequired()

Returns an AuthRequiredResponse object that can be used to determine if authentication is required to connect to the server. The AuthRequiredResponse object hods the 'salt' and 'secret' that will be required for authentication in the case that it is required throws an Exception if there is a problem or error returned by the server. Returns an AuthRequiredResponse object.

Implementation

Future<AuthRequiredResponse> getAuthRequired() async {
  var authRequired = AuthRequiredResponse.init();

  var messageId = sendCommand({'request-type': 'GetAuthRequired'});

  await for (String message in broadcast) {
    authRequired = AuthRequiredResponse.fromJson(jsonDecode(message));

    if (!authRequired.status) {
      throw Exception(
          'Server returned error to GetAuthRequiredResponse request: $message');
    }

    if (authRequired.messageId == messageId) {
      break;
    }
  }

  return authRequired;
}