You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
after that i have running below command in my terminal as per example given in your page.
dart
dart pub run build_runner build
flutter
flutter pub run build_runner build
after running above command i am getting this file which name is "RestClient.g.dart" here i have attach that file for your reference.
Note : I have just add code in .txt file becuase .dart extension not supported in github to upload file.
Now when i have running this code in my project i have faced this error in my console.
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: NoSuchMethodError: Class 'int' has no instance method 'toJson'.
E/flutter (20220): Receiver: 3594032520134656
E/flutter (20220): Tried calling: toJson()
E/flutter (20220): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
_RestClient.apiGetMyProfile (package:flutter_asdf/rest_client.g.dart:91:45)
and this error in this line
i have checked more in your example as i have not mentioned data type in query param. that's why this .toJson() method add in RestClient_g.dart file generate with above .toJson() method. now when i have given any type like String, Int then it will work.
I have used this package with latest version of this package.
Steps to reproduce the behavior:
@RESTapi(baseUrl: 'https://5d42a6e2bc64f90014a56ca0.mockapi.io/api/v1/')
abstract class RestClient {
factory RestClient(Dio dio, {String baseUrl}) = _RestClient;
@get('https://httpbin.org/get')
Future namedExample(
@query('apikey') apiKey);
}
dart
dart pub run build_runner build
flutter
flutter pub run build_runner build
Note : I have just add code in .txt file becuase .dart extension not supported in github to upload file.
RestClient_g.txt
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: NoSuchMethodError: Class 'int' has no instance method 'toJson'.
E/flutter (20220): Receiver: 3594032520134656
E/flutter (20220): Tried calling: toJson()
E/flutter (20220): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
_RestClient.apiGetMyProfile (package:flutter_asdf/rest_client.g.dart:91:45)
and this error in this line
@get('https://httpbin.org/get')
Future namedExample(
@query('apikey') apiKey);
My Question is that what if i want to make dynamic suppose i do not want to specify any data type then how to resolve this error.
Expected behavior
Not above error come.
The text was updated successfully, but these errors were encountered: