responseFactory method Null safety

Map<String, dynamic> responseFactory(
  1. Response response
)

Implementation

Map<String, dynamic> responseFactory(Response response) {
  dynamic dataMap;
  if (response.data != null && response.data != '') {
    if (response.statusCode == 302) {
      if (response.headers['location'] != null) {
        List<String> locactionList =
            response.headers['location'] as List<String>;
        final location = locactionList[0];
        dataMap = {'location': location};
      }
    } else {
      String dataStr = json.encode(response.data);
      dataMap = json.decode(dataStr);
    }
  }
  Map<String, dynamic> result = {
    'data': dataMap,
    'statusCode': response.statusCode,
    'statusMessage': response.statusMessage
  };
  return result;
}