getStarshipsItem static method

Future<StarshipsItem> getStarshipsItem(
  1. {int id,
  2. String url}
)

Returns a StarshipsItem

Implementation

static Future<StarshipsItem> getStarshipsItem({int id, String url}) {
  assert(id != null || url != null);

  http.Client httpClient = http.Client();
  String urlRequest = (url == null
      ? _baseUrl +
          _resourceStarships +
          (id == null ? "" : id.toString() + "/")
      : url);
  return httpClient.get(urlRequest).then((response) {
    String responseBody = utf8.decode(response.bodyBytes);
    if (response.statusCode == 200) {
      var map = json.decode(responseBody);
      return StarshipsItem(map);
    }
    throw ("code: ${response.statusCode}, message: $responseBody");
  });
}