Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support flutter web for native_dio_adapter #2133

Closed
ABausG opened this issue Mar 12, 2024 · 6 comments
Closed

Support flutter web for native_dio_adapter #2133

ABausG opened this issue Mar 12, 2024 · 6 comments

Comments

@ABausG
Copy link

ABausG commented Mar 12, 2024

Request Statement

Right now Flutter Web Projects fail to build as there are import chains pointing towards dart:ffi

Target dart2js failed: ProcessException: Process exited abnormally with exit code -2:
           ../../../../.pub-cache/hosted/pub.dev/cupertino_http-1.3.0/lib/src/cupertino_api.dart:30:8:
           Error: Dart library 'dart:ffi' is not available on this platform.
           import 'dart:ffi';
                  ^
           Info: The unavailable library 'dart:ffi' is imported through these packages:
           
               main.dart => package:my_app_packages => package:native_dio_adapter => package:cronet_http => package:jni => dart:ffi

Solution Brainstorm

No response

@ABausG ABausG added the s: feature This issue indicates a feature request label Mar 12, 2024
@AlexV525
Copy link
Member

Please submit related issues to the https://github.com/dart-lang/http repo.

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2024
@AlexV525 AlexV525 added i: out of support and removed s: feature This issue indicates a feature request labels Mar 12, 2024
@ABausG
Copy link
Author

ABausG commented Mar 12, 2024

@AlexV525 This is not about the dart-lang/http client though but about native_dio_adapter

We recently added native_dio_adapter to improve the http adapter on ios builds. Unfortunately that now breaks our web builds due to the error that I added to the description.

I think it would be awesome if this plugin could be used when also using Flutter web. So adding it to this section:

platforms:
android:
ios:
linux:
macos:
windows:

As well as making sure that a working http client is being used on flutter web.

As a first step it would be great to just get compiling working so lines where NativeAdapter() is created could be checked with !kIsWeb

@kuhnroyal
Copy link
Member

The native adapter does not support web, you can use the default BrowserHttpClientAdapter on web.
You can easily switch the implementation of the adapter yourself depending on the platform.

@ABausG
Copy link
Author

ABausG commented Mar 12, 2024

Yes but the issue comes up at compile time

@kuhnroyal
Copy link
Member

You can use a conditional import in the same way dio does it be default, you only have to change the adapters. See the imports here https://github.com/cfug/dio/blob/main/dio/lib/src/adapter.dart#L10 and the createAdapter() function.

@ABausG
Copy link
Author

ABausG commented Mar 12, 2024

I'll check again tomorrow as I also think that @nottmey has been trying to find a solution for this problem.

Right now the problem showed up when running flutter build web and point to an issue within pub getting the dependencies so even before it would be solvable with a conditional import.
I'll also see if I can get an example going where this is can be easily reproduced!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants