Closed salhugues closed 5 years ago
Hello I have NoSuchMethod error when I call a method from my Api. I created another service with my custom object and it give me this error.
Dart Error: Unhandled exception: NoSuchMethodError: The method 'get' was called on null. Receiver: null Tried calling: get("https://api.themoviedb.org/3/search/movie?api_key=lmkjlkda671719d52bc2&language=en-US&query=Avenger", headers: _LinkedHashMap len:0) #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5) #1 Get._send (package:jaguar_resty/routes/routes.dart:424:40) <asynchronous suspension> #2 Get.go (package:jaguar_resty/routes/routes.dart:434:41) #3 _TmDbApi&ApiClient&_$TmDbApiClient.searchMovies (file:///Users/hbadzoukoula/AndroidStudioProjects/the_app-android/the_mobility_app/lib/data/store/net/chopper/api/tmdb_api.jretro.dart:13:16) <asynchronous suspension> #4 ProjectPresenter.searchMovies (package:the_mobility_app/ui/screenproject/presenter/project_presenter.dart:41:9) <asynchronous suspension> #5 _ScreenProjectState.initState (package:the_mobility_app/ui/screen_project.dart:29:16) #6 StatefulElement._<…>
Here is my code for Api:
@GenApiClient(path: "/") class TmDbApi extends ApiClient with _$TmDbApiClient { final resty.Route base; TmDbApi(this.base); @GetReq(path: "3/search/movie") Future<TmDbMovieResult> searchMovies(@QueryMap() Map<String, String> keys); }
And here is how I call my method:
Map<String, String> tmtDbParams = Map(); tmtDbParams["api_key"] = "klfdjjmfjnvbcbbdndcosdlxms; tmtDbParams["language"] = "en-US; tmtDbParams["query"] = query; final repo = JsonRepo()..add(TmDbMovieSerializer())..add(TmDbMovieResultSerializer()); var api = TmDbApi(route(StringResources.TMDB_BASE_URL))..jsonConverter = repo; api.searchMovies(tmtDbParams).then((onMoviesResult) { return onMoviesResult.results; });
Thanks for your help.
add globalClient = IOClient() and it should work :)
globalClient = IOClient()
Wow thank you it worked, you lit up my day.
Hello I have NoSuchMethod error when I call a method from my Api. I created another service with my custom object and it give me this error.
Here is my code for Api:
And here is how I call my method:
Thanks for your help.