changeActiveProfile method Null safety

Future<bool> changeActiveProfile(
  1. int profilesId
)

Change the active profile for the current user. Will throw an Exception if the request fails or if the selected id is incorrect. Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#change-active-profile.

Implementation

Future<bool> changeActiveProfile(int profilesId) 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.post(
    Uri.parse('$baseUrl/changeActiveProfile'),
    headers: headers,
    body: json.encode({'profiles_id': profilesId}),
  );

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

  return true;
}