dio icon indicating copy to clipboard operation
dio copied to clipboard

The argument type 'HttpClientResponse' can't be assigned to the parameter type 'Stream<Uint8List>'

Open pushangupta opened this issue 7 years ago • 26 comments

New Issue Checklist

  • [x] I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name e.g. flutter / ios / android
Platform Version e.g. 1.5.0 / 12.0 / 9.0
Dio Version e.g. 2.1.0 / 1.0.17
Android Studio / Xcode Version e.g. Android Studio 3.3.2 / Xcode 10.2.1
Repro rate e.g. all the time (100%) / sometimes x% / only once
Repro with our demo prj e.g. does it happen with our demo project?
Demo project link e.g. link to a demo project that highlights the issue

Issue Description and Steps

Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.

pushangupta avatar Jul 04 '19 14:07 pushangupta

file:///Users/mac/flutter/.pub-cache/hosted/pub.dartlang.org/dio-2.1.9/lib/src/adapter.dart:161:7: Error: The argument type 'HttpClientResponse' can't be assigned to the parameter type 'Stream<Uint8List>'.

I just upgraded flutter and this error showed

pushangupta avatar Jul 04 '19 14:07 pushangupta

me too.

/.pub-cache/hosted/pub.flutter-io.cn/dio-2.1.9/lib/src/adapter.dart:161:7: Error: The argument type 'HttpClientResponse' can't be assigned to the parameter type 'Stream'.

  • 'HttpClientResponse' is from 'dart:_http'.
  • 'Stream' is from 'dart:async'.
  • 'Uint8List' is from 'dart:typed_data'. Try changing the type of the parameter, or casting the argument to 'Stream'. responseStream, ^

renjunok avatar Jul 04 '19 14:07 renjunok

This has broken my entire app :(

pushangupta avatar Jul 04 '19 14:07 pushangupta

Same here with a Dart package, not a Flutter app

synw avatar Jul 04 '19 15:07 synw

I have the same issue

keyduq avatar Jul 04 '19 15:07 keyduq

I managed to build the app by casting

responseStream as Stream<Uint8List>,

on line 161.

But now I get this error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: DioError [DioErrorType.DEFAULT]: RangeError (index): Invalid value: Only valid value is 0: 1#0 List.[] (dart:core-patch/growable_array.dart:145:60)

pushangupta avatar Jul 04 '19 15:07 pushangupta

I managed to build the app by casting

responseStream as Stream<Uint8List>,

on line 161.

But now I get this error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: DioError [DioErrorType.DEFAULT]: RangeError (index): Invalid value: Only valid value is 0: 1#0 List.[] (dart:core-patch/growable_array.dart:145:60)

Casting it as Stream<List<int>> according to this breaking change https://github.com/dart-lang/co19/issues/383 works on my side

keyduq avatar Jul 04 '19 15:07 keyduq

@keyduq Could you describe a little?

pushangupta avatar Jul 04 '19 15:07 pushangupta

@pushangupta From what I understand the issue is because there is a breaking change on Dart language where HttpRequest and HttpClientResponse now returns Stream<UInt8List> instead of Stream<List<int>>, the workaround is to cast Stream<UInt8List> as Stream<List<int>> so I just did the same thing that you do but instead cast it as Stream<List<int>>.

keyduq avatar Jul 04 '19 15:07 keyduq

@keyduq It still doesn't make any requests. I made change on line 161 in adapter file. Did you do the same just instead of Stream<UInt8List>, you did Stream<List<int>>?

Can you please share the changes you made?

pushangupta avatar Jul 04 '19 16:07 pushangupta

@pushangupta I have changed the line 161 in adapter.dart to responseStream as Stream<List<int>>, and works on my side.

keyduq avatar Jul 04 '19 16:07 keyduq

@keyduq strange! It doesn't work for me

pushangupta avatar Jul 04 '19 16:07 pushangupta

I was moments away from launching my app on the Play Store when I got this error on build. My error was thrown in adapter.dart. I followed the commit and undid the changes made to Stream. I came here to unload my frustrations when I saw @keyduq solution. I can confirm undoing the commit in adapter.dart will solve the problem. To the one who made the commit, were you the one at cloudflare the other day?

badrobot15 avatar Jul 04 '19 16:07 badrobot15

@pushangupta try this steps:

  1. Make sure that you set Dio version explicitly to 2.1.8, in pubspec.yaml set dio: 2.1.8
  2. Change the line 161 of adapter.dart in flutter/.pub-cache/hosted/pub.dartlang.org/dio-2.1.8/lib/src to responseStream as Stream<List<int>>,

With version 2.1.9 seems to not work out this solution.

keyduq avatar Jul 04 '19 18:07 keyduq

@keyduq Hi, I tried your solution and it solved this issue but afterwards I get this error.

Unhandled Exception: DioError [DioErrorType.DEFAULT]: type '_HttpClientResponse' is not a subtype of type 'Stream<Uint8List>'#0 DefaultHttpClientAdapter.fetch (package:dio/src/adapter.dart:161:22)

svmvnthvs avatar Jul 04 '19 18:07 svmvnthvs

@keyduq Yes thats the difference between yours and mine :). But alas! it doesn't work either

pushangupta avatar Jul 04 '19 19:07 pushangupta

urgency

JunevaYang avatar Jul 04 '19 20:07 JunevaYang

@keyduq I tried your solution on version 2.1.9 and it works!!

jctaoo avatar Jul 04 '19 23:07 jctaoo

I have changed the line 161 in adapter.dart to responseStream as Stream<List>, then DioError [DioErrorType.DEFAULT]: type '_HttpClientResponse' is not a subtype of type 'Stream'#0

williamjohn2008 avatar Jul 05 '19 00:07 williamjohn2008

This should be flagged as a breaking change in the changelog for the version 2.1.9.

A quick workaround as of now, if you don't want to refactor your code, is to set your dio version to 2.1.8 instead of ^2.x.x.

miguelpruivo avatar Jul 05 '19 00:07 miguelpruivo