0

Trying to use retrofit with injectable but can´t implement because when I put "@Singleton" annotation on the generated retrofit code, it gets immediately deleted on save.

This is original the code:

part 'api_service.g.dart';

@RestApi(baseUrl: kBaseUrl)
abstract class ApiService {
 factory ApiService(Dio dio, {String baseUrl}) = _ApiService;

 @POST('/Authentication/Token')
 Future<HttpResponse<User>> logInWithUsernameAndPassword(
   @Field("Username") String username,
   @Field("Password") String password,
   @Field("Device") String device,
 );
}

How could I send it as a singleton with injectable?

Thanks in advance.

P.S. I saw this answer Flutter - using retrofit with injectable but couldn't figure out how to implement it in my case.

  • Why would you try to modify the generated code manually? That's *never* a good idea. You probably want `ApiService` as singleton. Why not use the annotation on that class? – Riwen Jan 19 '23 at 08:22

0 Answers0