I am migrating my flutter project to 3.3.0
and i am calling API with retrofit
which was working fine, after upgrading all packages i delete .g.dart file and run the following command to rebuild the .g.dart file
flutter pub run build_runner build
it thrown the following error.
Error: No named parameter with the name 'autoCastResponse'.
autoCastResponse: annotation?.peek('autoCastResponse')?.boolValue,
^^^^^^^^^^^^^^^^
/E:/ahmad/Android/Android%20Bundle%20Setup/flutter/.pub-cache/hosted/pub.dartlang.org/retrofit-3.3.0/lib/http.dart:66:9: Context: Found this candidate, but th
e arguments don't match.
const RestApi({
^^^^^^^
/E:/ahmad/Android/Android%20Bundle%20Setup/flutter/.pub-cache/hosted/pub.dartlang.org/retrofit_generator-4.1.2/lib/src/generator.dart:494:27: Error: The getter 'autoCastResponse' isn't defined for the class 'RestApi'.
- 'RestApi' is from 'package:retrofit/http.dart' ('/E:/ahmad/Android/Android%20Bundle%20Setup/flutter/.pubcache/hosted/pub.dartlang.org/retrofit-3.3.0/lib/http.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'autoCastResponse'.
(clientAnnotation.autoCastResponse ?? true);
^^^^^^^^^^^^^^^^
[INFO] Precompiling build script... completed, took 900ms
[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
pub finished with exit code 78
I also try this command flutter packages pub run build_runner build --delete-conflicting-outputs
But the result remains the same.
Here is how my abstract class looks like,
part 'rest_client.g.dart';
@RestApi(baseUrl: "https://myapi.com/")
abstract class RestClient {
factory RestClient(Dio dio, {String baseUrl}) = _RestClient;
@POST("/Flag")
Future<LoginResponse> login(@Body() LoginRequest loginRequest)`;}`
These are my packages version:
retrofit: ^3.3.0
dev_dependencies:
flutter_test:
sdk: flutter
retrofit_generator: ^4.1.2
build_runner: ^2.2.1
json_serializable: ^6.4.1
dependency_overrides:
analyzer: '5.1.0'
According to this githubLink
retrofit: 3.3.0
had bugs and the author forgot to publish the generator accordingly. So after resolving that bug using retrofit: ^3.3.1
and retrofit_generator: 4.2.0
is working fine