searchItems method Null safety

Future<Map<String, dynamic>> searchItems(
  1. GlpiItemType itemType,
  2. {List<GlpiSearchCriteria>? criteria,
  3. List<GlpiSearchCriteria>? metaCriteria,
  4. int sort = 1,
  5. String order = 'ASC',
  6. int rangeStart = 0,
  7. int rangeLimit = 50,
  8. List<String>? forceDisplay = const [],
  9. bool rawData = false,
  10. bool withIndexes = false,
  11. bool uidCols = false,
  12. bool giveItems = false}
)

** This method is untested for the moment ** Return items found using the GLPI searchEngine Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#search-items

Implementation

Future<Map<String, dynamic>> searchItems(
  GlpiItemType itemType, {
  List<GlpiSearchCriteria>? criteria,
  List<GlpiSearchCriteria>? metaCriteria,
  int sort = 1,
  String order = 'ASC',
  int rangeStart = 0,
  int rangeLimit = 50,
  List<String>? forceDisplay = const [],
  bool rawData = false,
  bool withIndexes = false,
  bool uidCols = false,
  bool giveItems = false,
}) 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/searchItems/${itemType.toString().split('.').last}?sort=$sort&order=$order&range_start=$rangeStart&range_limit=$rangeLimit&raw_data=$rawData&with_indexes=$withIndexes&uid_cols=$uidCols&give_items=$giveItems');

  if (criteria != null) {
    for (var i = 0; i < criteria.length; i++) {
      uri.queryParameters.addAll(criteria[i].toUrlParameters(i));
    }
  }

  if (metaCriteria != null) {
    for (var i = 0; i < metaCriteria.length; i++) {
      uri.queryParameters.addAll(metaCriteria[i].toUrlParameters(i));
    }
  }

  if (forceDisplay != null) {
    for (var i = 0; i < forceDisplay.length; i++) {
      uri.queryParameters.addAll({'force_display[$i]': forceDisplay[i]});
    }
  }

  final response = await http.get(uri, headers: headers);

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

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