The argument type 'HttpClientResponse' can't be assigned to the parameter type 'Stream<Uint8List>'
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.
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
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, ^
This has broken my entire app :(
Same here with a Dart package, not a Flutter app
I have the same issue
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)
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 Could you describe a little?
@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 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 I have changed the line 161 in adapter.dart to
responseStream as Stream<List<int>>,
and works on my side.
@keyduq strange! It doesn't work for me
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?
@pushangupta try this steps:
- Make sure that you set Dio version explicitly to 2.1.8, in
pubspec.yamlsetdio: 2.1.8 - Change the line 161 of adapter.dart in
flutter/.pub-cache/hosted/pub.dartlang.org/dio-2.1.8/lib/srctoresponseStream as Stream<List<int>>,
With version 2.1.9 seems to not work out this solution.
@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)
@keyduq Yes thats the difference between yours and mine :). But alas! it doesn't work either
urgency
@keyduq I tried your solution on version 2.1.9 and it works!!
I have changed the line 161 in adapter.dart to responseStream as Stream<List
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.