streamedResponseAjax<T> function
Sends a request and lets the caller read the response body incrementally instead of buffering it — the streaming-response counterpart to ajax (e.g. for Server-Sent Events / chunked responses).
onResponse is given the http.StreamedResponse; consume its
http.StreamedResponse.stream (parse SSE, forward chunks, …) and
return when done. Its result becomes this call's result.
The connection — and the timeout hard force-close — stays alive
until onResponse completes; the underlying HttpClient is closed
afterward, so don't retain the stream past onResponse. As with
ajax, an exceeded timeout force-closes the socket and throws
TimeoutException.
Unlike ajax, the status code is NOT pre-checked: an error response
still invokes onResponse (the error body may stream in), so inspect
http.StreamedResponse.statusCode yourself.
Don't set Content-Length in headers — it's auto-computed from
the encoded body.
Implementation
Future<T> streamedResponseAjax<T>(Uri url,
Future<T> Function(http.StreamedResponse resp) onResponse, {
String method = "GET", List<int>? data, String? body,
Map<String, String>? headers, Duration? timeout})
=> _ajax(url, method: method, data: data, body: body, headers: headers,
timeout: timeout, getResponse: onResponse);