I am trying to use universal_io for my flutter project in Web. At the same time, I am using injectable. However, in the generated file of injectable, HttpClient is always recognised from dart:io and eventually throw some mismatch errors. At the moment, I have to manually update the generated file to get my app working. Not sure if there is any better way to resolve it. Thank you.
Here is my code
I created a regitser_module.dart
import 'package:injectable/injectable.dart';
import 'package:universal_io/io.dart';
@module
abstract class RegisterModule {
//add http client
@lazySingleton
HttpClient get httpClient => newUniversalHttpClient();
}
class $RegisterModule extends RegisterModule {}
and then run flutter packages pub run build_runner watch to generate the file for injectable.
However, in the injectable.config.dart file, it has
import 'dart:io' as _i6;
...
gh.lazySingleton<_i6.HttpClient>(() => registerModule.httpClient);
When I start running the app, I get the following error.
lib/injectable.config.dart:88:55: Error: The argument type 'HttpClient/*1*/' can't be assigned to the parameter type 'HttpClient/*2*/'.
- 'HttpClient/*1*/' is from 'dart:_http'.
- 'HttpClient/*2*/' is from 'package:universal_io/src/http_client.dart' ('/D:/pub_cache/hosted/pub.dev/universal_io-2.2.2/lib/src/http_client.dart').
() => _i15.GeneralServerService(httpClient: gh<_i6.HttpClient>()));
^
lib/injectable.config.dart:90:21: Error: The argument type 'HttpClient/*1*/' can't be assigned to the parameter type 'HttpClient/*2*/'.
- 'HttpClient/*1*/' is from 'dart:_http'.
- 'HttpClient/*2*/' is from 'package:universal_io/src/http_client.dart' ('/D:/pub_cache/hosted/pub.dev/universal_io-2.2.2/lib/src/http_client.dart').
httpClient: gh<_i6.HttpClient>(),
^
Failed to compile application.