0

Based on the two images here that I screenshot, I'm confused about making RestClient in Retrofit. When I deleted the Post Method, the part file (api_service.g.dart) didn't get an error. Look at this image : enter image description here

But when I add Post Method, the part file (api_service.g.dart) will be error. Looks like this: enter image description here

The error is:

error: Target of URI hasn't been generated: 'api_service.g.dart'. (uri_has_not_been_generated at [apps] lib\data\remote\api_service.dart:6)

and

error: The name '_RestClient' isn't a type and can't be used in a redirected constructor. (redirect_to_non_class at [apps] lib\data\remote\api_service.dart:11)

So, how is the solution? Thanks in advance

Lukmanpryg
  • 166
  • 2
  • 15

3 Answers3

1

Check the build_runner log. If the file is not generated there may be an error in your code that prevents the generator to run successfully.

Christopher Moore
  • 15,626
  • 10
  • 42
  • 52
Fran
  • 181
  • 8
  • I've got this error while generating :[SEVERE] retrofit_generator:retrofit on lib/data/remote/api_service.dart: Error running RetrofitGenerator NoSuchMethodError: Class 'InterfaceTypeImpl' has no instance method 'getDisplayString'. Receiver: Instance of 'InterfaceTypeImpl' Tried calling: getDisplayString(withNullability: false) – Lukmanpryg Nov 17 '20 at 00:53
  • 1
    It's infuriating that there's no error reported when running `flutter pub run build_runner build --delete-conflicting-outputs`, but removing the problematic code and re-running this command works! – dan Jan 30 '22 at 00:25
1

Finally it solved by upgrading all version like retrofit, retrofit_generator and build_runner. Thanks everyone

Lukmanpryg
  • 166
  • 2
  • 15
1
  @GET("player_api.php?")
  Future<List<dynamic>> getbyAction(@Query("username") String username,
      @Query("password") String password, @Query("action") String action);

change Future<List<dynamic>> to Future<dynamic> than try to run

flutter pub run build_runner build --delete-conflicting-outputs 
Sajjad Javed
  • 139
  • 2
  • 14