isNameAvailable function Null safety

Future<bool> isNameAvailable(
  1. String name,
  2. String accessToken
)

Checks whether or not given name is available or not. A name must be at least 3 characters and at most 16 characters long and not include any invalid characters to be valid. If your access token is invalid, this will silently fail and return false.

Implementation

Future<bool> isNameAvailable(String name, String accessToken) async {
  final response = await request(
      http.get, _minecraftServicesApi, 'minecraft/profile/name/$name/available',
      headers: {'authorization': 'Bearer $accessToken'});
  if (response.statusCode == 401) return false;
  final body = parseResponseMap(response);
  if (response.statusCode == 429) {
    throw TooManyRequestsException(body['errorMessage']);
  }
  // Can also be 'DUPLICATE' (already taken) or
  // 'NOT_ALLOWED' (blocked by name filter).
  return body['status'] == 'AVAILABLE';
}