getGroup method Null safety

Future<Group?> getGroup(
  1. String uuid,
  2. {bool useLogin = false}
)

Gets information about a Scanlation Group

Requires group's uuid

Returns Null if no results

Implementation

Future<Group?> getGroup(String uuid, {bool useLogin = false}) async {
  var res;
  if (token != '' && useLogin) {
    res = await http.get(Uri.parse('  $uuid'), headers: {
      HttpHeaders.authorizationHeader: 'Bearer $token',
      HttpHeaders.userAgentHeader: 'mangadex_dart_api/1.0'
    });
  } else {
    res = await http.get(Uri.parse('https://api.mangadex.org/group/$uuid'),
        headers: {HttpHeaders.userAgentHeader: 'mangadex_dart_api/1.0'});
  }
  var data = jsonDecode(res.body)['data'];
  if (res.statusCode == 403 && res.headers['X-Captcha-Sitekey'] != null) {
    throw CaptchaException(res.headers['X-Captcha-Sitekey'].toString(),
        message:
            'You need to solve a captcha, check `.sitekey` for the sitekey.');
  }
  if (res.statusCode == 404) {
    return null;
  }
  var group = Group(
      id: data['id'],
      name: data['attributes']['name'],
      isLocked: data['attributes']['locked'],
      createdAt: data['attributes']['createdAt'],
      updatedAt: data['attributes']['updatedAt'],
      description: data['attributes']['description'],
      website: data['attributes']['website'],
      ircChannel: data['attributes']['ircChannel'],
      ircServer: data['attributes']['ircServer'],
      discord: data['attributes']['discord'],
      contactEmail: data['attributes']['contactEmail'],
      leader: User(
          id: data['attributes']['leader']['id'],
          username: data['attributes']['leader']['attributes']['username']));
  return group;
}