Warm tip: This article is reproduced from stackoverflow.com, please click
dart flutter http httpclient

HttpClientResponse Error while Listen Data

发布于 2020-03-27 10:31:47

Problem

I get response from HttpClientResponse After that trying to perform listen like:

//... your code
response.transform(utf8.decoder).listen( (data) {
   //... your code
})
//... your code

Error(s)

The argument type 'Utf8Decoder' can't be assigned to the parameter type 'StreamTransformer<Uint8List, dynamic>'

Some Extra Detail(s)

  • Flutter Commit at 4cd12fc8b
  • Previously it was working fine.
Questioner
dileep
Viewed
107
Sirajudheen Abdul Rahiman 2019-07-03 23:52

This implementation is changed after fixing a bug in Stream handling.

Following is the changed request raised in Flutter community - https://github.com/dart-lang/sdk/issues/36900

You can fix this issue with following changes

request.close().then((response){
  response.cast<List<int>>().transform(utf8.decoder).listen((content) {
        return content;
      });
});

For reference : https://github.com/dart-lang/co19/pull/384