BrowserHttpClientAdapter() error in web.
Package
dio
Version
5.6.0
Operating-System
Web
Adapter
Default Dio
Output of flutter doctor -v
No response
Dart Version
3.5.0
Steps to Reproduce
BrowserHttpClientAdapter adapter = BrowserHttpClientAdapter(); adapter.withCredentials = true; dio.httpClientAdapter = adapter;
Expected Result
no error and work well.
Actual Result
TypeError: Cannot read properties of undefined (reading 'new') ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ #0 fortex7/packages/fortexmobile/common/network/web/web_platform.dart.lib.js 18:57 createClientAdapter
in flutter 3.22.3, it work well
flutter: 3.24.0
Could you share the resolved version of dio and dio_web_adapter in your pubspec.lock?
Hi bro, I also faced this error:
dio:
dependency: "direct main"
description:
name: dio
sha256: "0dfb6b6a1979dac1c1245e17cef824d7b452ea29bd33d3467269f9bef3715fb0"
url: "https://pub.dev"
source: hosted
version: "5.6.0"
dio_web_adapter:
dependency: transitive
description:
name: dio_web_adapter
sha256: "33259a9276d6cea88774a0000cfae0d861003497755969c92faa223108620dc8"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
I'm getting the normal result using the example in the repo: https://github.com/cfug/dio/tree/main/example_flutter_app
Could someone provide a standalone runnable minimal reproducible example?
Here is the code where I am encountering the error: link to code.
It looks like a Dart bug, filed dart-lang/sdk#56498.
Meanwhile, a workaround could be:
HttpClientAdapter makeHttpClientAdapter() {
final adapter = HttpClientAdapter() as BrowserHttpClientAdapter;
adapter.withCredentials = true;
return adapter;
}
Workaround stopped working for me, this worked:
class _Adapter extends BrowserHttpClientAdapter {
_Adapter() {
withCredentials = true;
}
}
Workaround stopped working for me, this worked:
class _Adapter extends BrowserHttpClientAdapter { _Adapter() { withCredentials = true; } }
How do you extend BrowserHttpClientAdapter? I get Uncaught TypeError when I run my app. Here is the complete code:
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:dio/browser.dart';
class CustomBrowserHttpClientAdapter extends BrowserHttpClientAdapter {
CustomBrowserHttpClientAdapter() {
withCredentials = true;
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Dio dio = Dio()..httpClientAdapter = CustomBrowserHttpClientAdapter();
return Container();
}
}
And here is the console output:
Uncaught TypeError: Class extends value undefined is not a constructor or null
at load__packages__didgah__main_test_dart (main_test.dart.lib.js:79:13)
Hi guys i have the same problem with:
flutter: 3.24.3 dart: 3.5.3 Dio: 5.7.0
class HttpClientBrowser with DioMixin implements HttpClient {
HttpClientBrowser(HttpSettings settings) {
options = settings.baseOptions;
httpClientAdapter = BrowserHttpClientAdapter();
interceptors.addAll(settings.interceptors);
}
}
any update on the bug?
The thread is locked until https://github.com/dart-lang/sdk/issues/56498 gets resolved.