deleteItems method Null safety

Future<List<Map<String, String>>> deleteItems(
  1. GlpiItemType itemType,
  2. String data
)

Return the ids of the items deleted with true is the deletion is complete. Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#delete-items

Implementation

Future<List<Map<String, String>>> deleteItems(
    GlpiItemType itemType, String data) 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 uri = Uri.parse('$baseUrl/${itemType.toString().split('.').last}');

  final response = await http.delete(uri, headers: headers, body: data);

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

  List<dynamic> decodedJson = json.decode(response.body);

  List<Map<String, String>> formatted = decodedJson.map((element) {
    return element as Map<String, String>;
  }).toList();

  return Future.value(formatted);
}