HttpClientResponse Error while Listen Data

2019-07-24 05:04发布

问题:

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.

回答1:

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