getVehiclesItem static method

Future<VehiclesItem> getVehiclesItem(
  1. {int id,
  2. String url}
)

Returns a VehiclesItem

Implementation

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

  http.Client httpClient = http.Client();
  String urlRequest = (url == null
      ? _baseUrl + _resourceVehicles + (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 VehiclesItem(map);
    }
    throw ("code: ${response.statusCode}, message: $responseBody");
  });
}