Home > Software design >  Flutter - using retrofit with injectable
Flutter - using retrofit with injectable

Time:07-10

I am trying to use retrofit along with injectable

I am following clean architecture, and in the repo class i want to inject the retrofit client but i cant annotate the client with injectable since its abstract and i cant annotate the implementation because it is generated

I tried to annotate the generated file but that wont work because it will remove my changes the next time build runner is called

is there a proper way to solve this problem

i wont post my code because there isnt much to it

CodePudding user response:

Yeah, you use the @module annotation and create a "RetrofitInjectableModule". As such:

@module  
abstract class RetrofitInjectableModule {  
   BackendService getService(ApiClient client, @factoryParam String url) => BackendService(client, url);  
}  

Where BackendService is your RestClient.

Read about @module on https://pub.dev/packages/injectable

  • Related