dio icon indicating copy to clipboard operation
dio copied to clipboard

native_dio_adapter does not support onReceiveProgress and onSendProgress

Open Vovcharaa opened this issue 1 year ago • 13 comments

Package

native_dio_adapter

Version

0.1.0

Output of flutter doctor -v

[✓] Flutter (Channel stable, 3.10.1, on macOS 13.4 22F66 darwin-arm64, locale en-UA)
    • Flutter version 3.10.1 on channel stable at /Users/vovchara/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d3d8effc68 (10 days ago), 2023-05-16 17:59:05 -0700
    • Engine revision b4fb11214d
    • Dart version 3.0.1
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/vovchara/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.78.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.64.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.4 22F66 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 113.0.5672.126

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Dart Version

3.0.1

Steps to Reproduce

Provide onReceiveProgress and/or onSendProgress callback to any request method.

Expected Result

Callback is called the same way as without native adapter.

Actual Result

Callback is called only once after download is done.

Vovcharaa avatar May 26 '23 19:05 Vovcharaa

Hey, native_dio_adapter is still experimental so some issues are to be expected.

Are you open to contribute this feature?

ueman avatar May 31 '23 17:05 ueman

@ueman While onReceiveProgress has a pretty straightforward fix (I'll create PR today for this), I am not sure about how to fix onSendProgress because adapter converts the request object to http package request for easy integration. There are also serious performance issues with downloading using dio_http2_adapter and onSendProgress seems to have the same issues as here (but I could not confirm it yet for sure). Should I create a separate issue for dio_http2_adapter?

Vovcharaa avatar Jun 01 '23 08:06 Vovcharaa

Awesome, thank you for the upcoming PR. Yes, please create a separate issue for dio_http2_adapter.

I am not sure about how to fix onSendProgress because adapter converts the request object to http package request for easy integration.

I was afraid of that. I think in the future we should get rid of that conversion layer, but that was the easiest way to get it working quickly. Additionally, while it's still experimental it can change at anytime, so using http as a target also kept the maintenance work to a minimum.

ueman avatar Jun 01 '23 08:06 ueman

I think in the future we should get rid of that conversion layer

That won't help to fix onSendProgress. cupertino_http and cronet_http drains the stream before sending the whole body to the native code. We need either to make PR with stream body implementation into their repo or create a new implementation of native clients here.

Vovcharaa avatar Jun 01 '23 20:06 Vovcharaa

Oh I didn't know that. Then there should be an issue on their repo about that problem.

ueman avatar Jun 01 '23 20:06 ueman

I think that is desired behavior for them. They don't have any use cases for request streams, as there is no way to set the request body as a stream in http package.

Vovcharaa avatar Jun 01 '23 21:06 Vovcharaa

I made a future request for cupertino_http package and when this is merged StreamingRequest will be working as intended. This should unblock the implementation of onSendProgress. https://github.com/dart-lang/http/issues/974 https://github.com/dart-lang/http/pull/975

Vovcharaa avatar Jun 30 '23 20:06 Vovcharaa

dart-lang/http#974 dart-lang/http#975

They don't seem to be blocking anymore. Would you take another look if it requires further implementations? @Vovcharaa

AlexV525 avatar Jul 19 '23 01:07 AlexV525

@AlexV525 It definitely requires implementation of the condition when to use StreamedRequest in native clients. Should it be when onSendProgress callback is provided? Or should we create a new field in RequestOptions for that?

Vovcharaa avatar Jul 19 '23 08:07 Vovcharaa

@AlexV525 https://github.com/dart-lang/http/issues/974#issuecomment-1641850725 This prevents onSendProgress from working correctly.

Vovcharaa avatar Jul 19 '23 10:07 Vovcharaa

That doesn't prevent implementing it in this native_dio_adapter tho. And then as soon as the cupertino_http package supports it, native_dio_adapter will too

ueman avatar Jul 19 '23 10:07 ueman

I agree. The only question is when we want to use StreamedRequest because for simple requests streams could be slower in the case of native clients.

https://github.com/dart-lang/http/blob/b2067710f88980fc0fee43ec3380bce089f001db/pkgs/cupertino_http/lib/src/cupertino_client.dart#L255-L256

Vovcharaa avatar Jul 19 '23 10:07 Vovcharaa

Should it be when onSendProgress callback is provided?

I think this would be good at this moment.

AlexV525 avatar Jul 23 '23 01:07 AlexV525