solveCaptcha method Null safety

Future<void> solveCaptcha(
  1. String captchaResult
)

Sends the captcha result to the API server

Automatically sends your session token if you are logged in

Throws an Exception if the captcha was solved incorrrectly

Implementation

Future<void> solveCaptcha(String captchaResult) async {
  var res;
  if (token != '') {
    res = await http.post(
      Uri.parse('https://api.mangadex.org/auth/solve'),
      headers: {
        HttpHeaders.authorizationHeader: 'Bearer $token',
        HttpHeaders.userAgentHeader: 'mangadex_dart_api/1.0'
      },
      body: '{"captchaChallenge":"$captchaResult"}',
    );
  } else {
    res = await http.post(Uri.parse('https://api.mangadex.org/auth/solve'),
        body: '{"captchaChallenge":"$captchaResult"}',
        headers: {HttpHeaders.userAgentHeader: 'mangadex_dart_api/1.0'});
  }
  var data = jsonDecode(res.body);
  if (res.statusCode == 400) {
    throw 'An error has happened: ${data["errors"][0]["title"]} - ${data["errors"][0]["detail"]}';
  }
}