I'm using http library in order to download an image.
final client = http.Client();
final _response = await client.send(http.Request('GET', Uri.parse("my_url")));
Listening way 1: (listen method)
int downloaded = 0;
_response.stream.listen((value) {
// this gets called 82 times and I receive actual image size
downloaded += value.length;
});
Listening way 2: (StreamBuilder widget)
int downloaded = 0;
StreamBuilder<List<int>>(
stream: _response.stream,
builder: (_, snapshot) {
// this gets called 11 times and I receive around 1/10 actual image size
if (snapshot.hasData) downloaded += snapshot.data.length;
return Container();
},
);
The question is why StreamBuilder's build() method isn't getting called that often when new data arrives, it simply defeats the purpose of being used as a widget.