loadDetail function

Future<Game> loadDetail(
  1. int id
)

get the Game from api with details

Implementation

Future<Game> loadDetail(int id) async {
  Response response = await RawgUtils.dio.get(
    '${RawgUtils.baseUrl}/games/$id',
    queryParameters: {
      "key": Rawg.key,
    },
    options: Options(
      validateStatus: (status) => true,
    ),
  );

  if (response.statusCode! != 200) {
    throw RawgException(
      "Request not in 200 OK",
      response.statusCode ?? -1,
    );
  }

  if (response.data["error"] != null || response.data["details"] != null) {
    throw RawgException(
      response.data["error"] ?? response.data["details"],
      response.statusCode ?? -1,
    );
  }

  return Game.fromJson(response.data);
}