diff --git a/plugins/native_dio_adapter/CHANGELOG.md b/plugins/native_dio_adapter/CHANGELOG.md index 1a678d84e..ccd405491 100644 --- a/plugins/native_dio_adapter/CHANGELOG.md +++ b/plugins/native_dio_adapter/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Replace `DioError` with `DioException`. +- Fix `onReceiveProgress` callback. ## 0.1.0 diff --git a/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart b/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart index df081f26b..a035f2c45 100644 --- a/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart +++ b/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart @@ -70,7 +70,7 @@ extension on StreamedResponse { ResponseBody toDioResponseBody() { final dioHeaders = headers.entries.map((e) => MapEntry(e.key, [e.value])); return ResponseBody( - Stream.fromFuture(stream.toBytes()), + stream.cast(), statusCode, headers: Map.fromEntries(dioHeaders), isRedirect: isRedirect, diff --git a/plugins/native_dio_adapter/test/conversion_layer_adapter_test.dart b/plugins/native_dio_adapter/test/conversion_layer_adapter_test.dart index a57bff61e..5de82452f 100644 --- a/plugins/native_dio_adapter/test/conversion_layer_adapter_test.dart +++ b/plugins/native_dio_adapter/test/conversion_layer_adapter_test.dart @@ -1,3 +1,5 @@ +import 'dart:typed_data'; + import 'package:dio/dio.dart'; import 'package:http/http.dart'; import 'package:native_dio_adapter/src/conversion_layer_adapter.dart'; @@ -36,4 +38,26 @@ void main() { expect(mock.request?.headers, {'foo': 'bar'}); }); + + test('download stream', () async { + final mock = ClientMock() + ..response = StreamedResponse( + Stream.fromIterable([ + Uint8List.fromList([10, 1]), + Uint8List.fromList([1, 4]), + Uint8List.fromList([5, 1]), + Uint8List.fromList([1, 1]), + Uint8List.fromList([2, 4]), + ]), + 200); + final cla = ConversionLayerAdapter(mock); + + final resp = await cla.fetch( + RequestOptions(path: ''), + null, + null, + ); + + expect(await resp.stream.length, 5); + }); }