getFlight method

Future<List<FlightContract>?> getFlight(
  1. FlightSearchByEnum searchBy,
  2. String searchParam, {
  3. DateTime? dateLocal,
  4. bool? withAircraftImage,
  5. bool? withLocation,
})

Flight status TIER 2

What is the flight status? or What is the flight schedule? Returns live flight status (if the flight is within the coverage and not in distant future), or flight schedule data otherwise. If dateLocal is specified, gets information about flight(s) departing or arriving on the day specified (local time). Otherwise, gets information about the status of flight(s) operating on the date of the nearest flight (either in past or in future). Flight can be searched by: * flight number it's being operated under; or * ATC-callsign it's being operated under; or * tail-number of the aircraft it's being operated by; or * Mode-S 24-bit ICAO Transponder address of the aircraft it's being operated by. Flight may include airport of arrival and departure, scheduled and actual times, flight status, type of aircraft, tail-number and aircraft image. Some flights may have partial information only. Information may be absent for either arrival or departure airport or can be without live updates of time and status. Check quality markers inside the response for more information. Normally, information with live status updates and estimated/actual arrival/departure times is only available for airports tracked live or with ADS-B by our system. Otherwise flight information will be with scheduled info only or absent. To check if an airport is tracked and on which level, use /health/services/airports/{icao}/feeds endpoint. You can also use /health/services/feeds/{service}/airports to get the list of covered airports. Read more about coverage and flight data limits here: https://www.aerodatabox.com/data-coverage. Aircraft images are being searched in external sources by certain criteria without any manual intervention. Therefore, false matches may be returned. Only images with licenses approved for commercial use are returned. Please be advised that you may be required to mention author attribution before using the image.

Parameters:

  • FlightSearchByEnum searchBy (required): Criteria to search flight by

  • String searchParam (required): Value of the search criteria. If searchBy is: * number, then this field shoud be Flight number (with or without spaces, IATA or ICAO, any case formats are acceptable, e.g. KL1395, Klm 1395) * callsign, then this field should be ATC call-sign of the flight (with or without spaces, any case formats are acceptable, e.g.AFL1482, nca 008X); * reg, then this field should be Aircraft tail-number (with or without spaces or dashes, any case formats are acceptable, e.g.PH-BXO, DeMhJ); * icao24, then this field should be Aircraft ICAO 24-bit Mode-S address specified in hexadecimal format (e.g. 484161, 483EFD).

  • DateTime dateLocal: Local date of departure or arrival (in format: YYYY-MM-DD, e.g.: 2019-08-29).

  • bool withAircraftImage: Should include aircraft image (default: false).

  • bool withLocation: Should include real-time positional data, e.g.: location, speed, altitude, etc., if available (default: false).

Implementation

Future<List<FlightContract>?> getFlight(
  FlightSearchByEnum searchBy,
  String searchParam, {
  DateTime? dateLocal,
  bool? withAircraftImage,
  bool? withLocation,
}) async {
  final response = await getFlightWithHttpInfo(
    searchBy,
    searchParam,
    dateLocal: dateLocal,
    withAircraftImage: withAircraftImage,
    withLocation: withLocation,
  );
  if (response.statusCode >= HttpStatus.badRequest) {
    throw ApiException(response.statusCode, await _decodeBodyBytes(response));
  }
  // When a remote server returns no body with a status of 204, we shall not decode it.
  // At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
  // FormatException when trying to decode an empty string.
  if (response.body.isNotEmpty &&
      response.statusCode != HttpStatus.noContent) {
    final responseBody = await _decodeBodyBytes(response);
    return (await apiClient.deserializeAsync(
            responseBody, 'List<FlightContract>') as List)
        .cast<FlightContract>()
        .toList(growable: false);
  }
  return null;
}