killSession method Null safety

Future<bool> killSession()

Return true if the client is successfully disconnected from the API. Will throw an Exception if the session can't be disconnected. Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#kill-session.

Implementation

Future<bool> killSession() async {
  if (_sessionToken == null) {
    throw Exception('No session token, initSession first');
  }

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

  final _response =
      await http.get(Uri.parse('$baseUrl/killSession'), headers: headers);

  if (_response.statusCode != 200) {
    throw Exception('${_response.statusCode} ${_response.body}');
  }

  _sessionToken = null;
  return true;
}