-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter Web buffering streamed/chunked data #593
Comments
This is mentioned as a limitation in the docs for http/lib/src/browser_client.dart Lines 27 to 29 in f93c76f
Streaming does not work for the browser client because it uses |
Please follow #595 for updates, but I don't expect anything in the short term. |
Thanks for the reply. I think i might have found a work around using dart:html.
Returned results: This code would need to be commented out, though, before compiling for android/ios as it will throw errors. The original code from my first question works fine for android/ios |
A workaround was necessary because the dart:html BrowserClient doesn't directly support streaming repsonses: flutter/flutter#86199 flutter/flutter#43343 Workaround idea: dart-lang/http#593 (comment)
I have a local server that will emit numbers 1-10 back to the app when hit. On Flutter android and ios devices, the app procceses each data chunk as they come and it works as expected. On the Flutter Web version, the data is buffered until the end of the stream AND THEN processes the data...how do I get Flutter Web to process each data chunk as they come and not buffer the stream, like the android and ios versions do?
sample code:
import 'package:http/http.dart' as http;
void _postIt() async {
syncingz = true;
http.Request request = http.Request('POST', url);
http.StreamedResponse response = await http.Client().send(request); // make a stream request
streamedRes = response.stream.listen( (value) { // listen to the stream
print(utf8.decode(value)); // print out each yield return as it arrives...in sequence
res = utf8.decode(value);
}
setState(() {}); // update flutter ui with each data chunk received
},
);
await streamedRes.asFuture();
print('all done');
streamedRes.cancel();
syncingz = false;
setState((){});
}
android ios results:
1
2
3
4...
all done
flutter web results:
12345678910
all done
The text was updated successfully, but these errors were encountered: