Jaguar-dart / client

Contains various packages for client side

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

runtime exception

cosouly opened this issue · comments

When I run the code copy from the retrofit example, It's print the error log below. How can I run it right?

[VERBOSE-2:shell.cc(186)] Dart Error: Unhandled exception:
NoSuchMethodError: The method 'get' was called on null.
Receiver: null
Tried calling: get("https://api.github.com/users/cosouly/followers", 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      _GithubApi&ApiClient&_$GithubApiClient.getFollowersById (file:///.../fm_app_demo/lib/home/apis/github_api.jretro.dart:16:16)
<asynchronous suspension>
#4      FollowersBase.getFollowers (package:fm_app_demo/home/modules/follower_store.dart:29:9)
#5      Followers.getFollowers (file:///Users/yang.luo/workspace/mine/flutter/fm_app_demo/lib/home/modules/follower_store.g.dart:31:20)
#6      _HomePageState.initState (package:fm_app_demo/home/pages/home_page.dart:22:15)
#7      StatefulElement._firstBuild (packag<…>
 1.7s

@cosouly You have to initialize globalClient before you make any requests as shown here:
https://github.com/Jaguar-dart/client/blob/master/retrofit/example/example.dart#L80

This will not be needed in future versions, however.

It's running okey, thank you!

Hello I have the same error. I create another service with my custom object and it give me this error. Here is my code:

@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);
}

Here is how I call my method:

Map<String, String> tmtDbParams = Map();
    tmtDbParams[StringResources.TMDB_API_KEY_PARAM] = StringResources.TMDB_API_KEY;
    tmtDbParams[StringResources.TMDB_LANGUAGE_PARAM] = StringResources.TMDB_LANGUAGE;
    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;
    });

Hello I have the same error. I create another service with my custom object and it give me this error. Here is my code:

@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);
}

Here is how I call my method:

Map<String, String> tmtDbParams = Map();
    tmtDbParams[StringResources.TMDB_API_KEY_PARAM] = StringResources.TMDB_API_KEY;
    tmtDbParams[StringResources.TMDB_LANGUAGE_PARAM] = StringResources.TMDB_LANGUAGE;
    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;
    });

See #48 (comment) , You must to initialize globalClient before you make any requests.