getFullSession method Null safety

Future<Map<String, dynamic>> getFullSession()

Return the session data include in the php $_SESSION. For the moment it's just a Map of the json response. Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#get-full-session.

Implementation

Future<Map<String, dynamic>> getFullSession() async {
  if (_sessionToken!.isEmpty) {
    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/getFullSession'), headers: headers);

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

  _session = json.decode(response.body);
  return Future.value(_session);
}