injectable icon indicating copy to clipboard operation
injectable copied to clipboard

Different return type

Open stepanzalis opened this issue 3 years ago • 2 comments

Hello 👋

in @module I have custom Dio client which is returns Future<Dio>,

@preResolve
Future<Dio> get dio => CustomDioClient.createDio();

and ApiClient which needs to have Dio instance like ApiClient get apiClient => ApiClient(injector<Dio>());

in .config it's generated like this: gh.factoryAsync<_i5.CustomDioClient>(() => _i5.CustomDioClient.createDio()); But I get error: Error: A value of type 'Future<Dio>' can't be returned from a function with return type 'Future<CustomDioClient>. I am not sure what I am doing wrong. Thanks for any advise 🙏

stepanzalis avatar Apr 01 '21 20:04 stepanzalis

@stepanzalis not sure what's going on here but why are you injecting Dio manually here? ApiClient get apiClient => ApiClient(injector<Dio>()); that might be the cause.

Milad-Akarie avatar Apr 02 '21 16:04 Milad-Akarie

ApiClient above is abstract class which will is generated and needs Dio as dependency. I also need to create my custom Dio client which has all interceptors etc. (CustomDioClient) which returns Future<Dio>. When I inject it to ApiClient, error says that I pass instance of CustomDioClient and not instance of Dio.

stepanzalis avatar Apr 03 '21 08:04 stepanzalis