Skip to content

Commit 971cbfc

Browse files
committed
fix cfug#365
1 parent a2ade28 commit 971cbfc

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

example/test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:typed_data';
2+
13
import 'package:dio/dio.dart';
24
void getHttp() async {
35
try {
@@ -9,5 +11,10 @@ void getHttp() async {
911
}
1012

1113
main() async{
12-
await getHttp();
14+
// await getHttp();
15+
// Stream<Uint8List> t =Stream.empty();
16+
// Stream<List<int>> v=Stream.empty();
17+
// print(v is Stream<Uint8List>);
18+
// print (t is Stream<List<int>> );
19+
// print(t is Stream<Uint8List>);
1320
}

package_src/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.1.11
2+
3+
- fix #365
4+
15
# 2.1.10
26

37
- fix #360

package_src/lib/src/adapter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class DefaultHttpClientAdapter extends HttpClientAdapter {
169169
} else {
170170
stream=responseStream.cast<Uint8List>();
171171
}
172+
172173
return ResponseBody(
173174
stream,
174175
responseStream.statusCode,

package_src/lib/src/dio.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -828,14 +828,14 @@ class Dio {
828828

829829
Future<Stream<Uint8List>> _transformData(RequestOptions options) async {
830830
var data = options.data;
831-
Uint8List bytes;
832-
Stream<Uint8List> stream;
831+
List<int> bytes;
832+
Stream stream;
833833
if (data != null && ["POST", "PUT", "PATCH", "DELETE"].contains(options.method)) {
834834
// Handle the FormData
835835
int length;
836836
if (data is Stream) {
837-
assert(data is Stream<Uint8List>,
838-
"Stream type must be `Stream<Uint8List>`, but ${data.runtimeType} is found.");
837+
assert(data is Stream<List>,
838+
"Stream type must be `Stream<List>`, but ${data.runtimeType} is found.");
839839
stream = data;
840840
options.headers.keys.any((String key) {
841841
if (key.toLowerCase() == HttpHeaders.contentLengthHeader) {
@@ -849,7 +849,7 @@ class Dio {
849849
options.headers[HttpHeaders.contentTypeHeader] =
850850
'multipart/form-data; boundary=${data.boundary.substring(2)}';
851851
}
852-
stream=data.stream.cast<Uint8List>();
852+
stream=data.stream;
853853
length = data.length;
854854
} else {
855855
// Call request transformer.
@@ -863,7 +863,7 @@ class Dio {
863863
// support data sending progress
864864
length = bytes.length;
865865

866-
var group = new List<Uint8List>();
866+
var group = List<List<int>>();
867867
const size = 1024;
868868
int groupCount = (bytes.length / size).ceil();
869869
for (int i = 0; i < groupCount; ++i) {
@@ -872,14 +872,15 @@ class Dio {
872872
}
873873
stream = Stream.fromIterable(group);
874874
}
875+
875876
options.headers[HttpHeaders.contentTypeHeader] ??=
876877
options.contentType.toString();
877878
if (length != null) {
878879
options.headers[HttpHeaders.contentLengthHeader] = length;
879880
}
880881
int complete = 0;
881882
Stream<Uint8List> byteStream =
882-
stream.transform(StreamTransformer.fromHandlers(
883+
stream.cast<Uint8List>().transform(StreamTransformer.fromHandlers(
883884
handleData: (data, sink) {
884885
if (options.cancelToken != null && options.cancelToken.isCancelled) {
885886
sink

package_src/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dio
22
description: A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.
3-
version: 2.1.10
3+
version: 2.1.11
44
homepage: https://github.com/flutterchina/dio
55
author: wendux <[email protected]>
66

0 commit comments

Comments
 (0)