downloadDocument method Null safety

Future<String> downloadDocument(
  1. int id
)

Allow to download a GlpiItemType.Document. id must be the id of the document to download. Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#download-a-document-file

Implementation

Future<String> downloadDocument(int id) async {
  if (_sessionToken!.isEmpty) {
    throw Exception('No session token, initSession first');
  }

  final Map<String, String> headers = {
    'Session-Token': _sessionToken!,
    'Content-Type': 'application/json',
    'Accept': 'application/octet-stream',
    ...?appToken != null ? {'App-Token': appToken!} : null,
  };

  final uri = Uri.parse('$baseUrl/Document/$id');

  final response = await http.get(uri, headers: headers);

  if (response.statusCode != 200 && response.statusCode != 207) {
    throw GlpiException.fromResponse(
        response.statusCode, json.decode(response.body));
  }

  return Future.value(response.body);
}