changeActiveEntities method Null safety

  1. @override
Future<bool> changeActiveEntities(
  1. dynamic entitiesId,
  2. {bool recursive = false}
)
override

Allow to change the active entity for the current user. entitiesId can either be the numerical id of the entity or all to load all the entities. recursive can be set to true to load all the sub-entities. 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-entities

Implementation

@override
Future<bool> changeActiveEntities(dynamic entitiesId,
    {bool recursive = false}) 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 _innerClient.post(
    Uri.parse('$host/changeActiveEntities'),
    headers: headers,
    body: json.encode({'entities_id': entitiesId, 'is_recursive': recursive}),
  );

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

  return true;
}