answerSecurityChallenges function Null safety

Future<bool> answerSecurityChallenges(
  1. String accessToken,
  2. List<SecurityChallenge> answers

Allows an authenticated user to verify their location by answering their security questions. You can get the security challenges through getSecurityChallenges. Also check if this is needed using areSecurityChallengesNeeded.


Future<bool> answerSecurityChallenges(
    String accessToken, List<SecurityChallenge> answers) async {
  /// Verify we have enough answers passed.
  if (answers.length != 3) {
    throw ArgumentError.value(
        answers, 'answers', 'We require at least 3 answers.');

  final headers = {
    'authorization': 'Bearer $accessToken',
    'content-type': 'application/json',
  final body = [for (final answer in answers) answer.asAnswerJson];
  final response = await requestBody(, _mojangApi, 'user/security/location', body,
      headers: headers);
  if (response.statusCode == 403) {
    throw ArgumentError.value(
        answers, 'answers', 'At least one answer was incorrect.');
  return response.statusCode == 204;