getMassiveActions method Null safety

Future<List<Map<String, String>>> getMassiveActions(
  1. GlpiItemType itemType,
  2. {bool isDeleted = false}
)

Return the availables massive actions for a given itemtype isDeleted (default false): Show specific actions for items in the trashbin Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#get-available-massive-actions-for-an-itemtype

Implementation

Future<List<Map<String, String>>> getMassiveActions(GlpiItemType itemType,
    {bool isDeleted = 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/getMassiveActions/${itemType.toString().split('.').last}?is_deleted=$isDeleted');

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

  if (response.statusCode != 200 && 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);
}