WeatherResponse.fromFlatBuffer constructor

WeatherResponse.fromFlatBuffer(
  1. Uint8List bytes
)

Implementation

factory WeatherResponse.fromFlatBuffer(Uint8List bytes) {
  int prefixed =
      BufferContext.fromBytes(bytes).buffer.getUint32(0, Endian.little);
  WeatherApiResponse response =
      WeatherApiResponse(bytes.sublist(4, prefixed + 4));

  return WeatherResponse._(
    latitude: response.latitude,
    longitude: response.longitude,
    elevation: response.elevation,
    generationTime: Duration(
      microseconds: (response.generationTimeMilliseconds * 1000).round(),
    ),
    utcOffset: Duration(seconds: response.utcOffsetSeconds),
    timezone: response.timezone,
    timezoneAbbreviation: response.timezoneAbbreviation,
    currentWeatherData: processSingle(response.current, Current.fromVariable),
    hourlyWeatherData: processMultiple(response.hourly, Hourly.fromVariable),
    dailyWeatherData: processMultiple(response.daily, Daily.fromVariable),
  );
}