open_meteo 2.0.1 copy "open_meteo: ^2.0.1" to clipboard
open_meteo: ^2.0.1 copied to clipboard

A simple, fast, asynchronous Dart/Flutter package for accessing the Open-Meteo API.

Open-Meteo API SDK #

A simple, fast, asynchronous Dart/Flutter package for accessing the Open-Meteo API.

All features from the Open-Meteo API have been implemented (some are limited). Be sure to read Open Meteo's Terms of Use before using this package in your project.

Top Contributors #


MathNerd28
🛠️ | 💛 v1.1.0 - v2

Usage & Docs #

Each of the nine features available in Open-Meteo is represented by its class: WeatherApi, HistoricalApi, EnsembleApi, ClimateApi, MarineApi, AirQualityApi, GeocodingApi, ElevationApi and FloodApi.

Note

All inputs to the API have been adapted to Dart-friendly variables. Time arguments are DateTime objects and many parameters have enum representations.

For example, to get the hourly temperature in Celsius in London, 2 meters above sea level using WeatherApi, and only get information from 2024-08-10 to 2024-08-12:

import 'package:open_meteo/open_meteo.dart';

void main() async {
  final weather = WeatherApi();
  final response = await weather.request(
    latitude: 52.52,
    longitude: 13.41,
    hourly: {WeatherHourly.temperature_2m},
    startDate: DateTime(2024, 8, 10),
    endDate: DateTime(2024, 8, 12),
    temperature_unit: TemperatureUnit.celsius,
  );
  final data = response.hourlyData[WeatherHourly.temperature_2m]!;
  final currentTemperature = data.values;

  print(currentTemperature);
}

In this example, the result is a Map<DateTime, double>:

{
  2024-08-08 05:00:00.000: 20.09549903869629,
  2024-08-08 06:00:00.000: 19.89550018310547,
  ...,
  2024-08-13 03:00:00.000: 18.788999557495117,
  2024-08-13 04:00:00.000: 17.288999557495117,
}

Tip

In each API, there are two main methods:

  • request returns a Dart object, and throws an exception if the API returns an error response, recommended for most use cases.

  • requestJson returns a JSON map, containing either the data or the raw error response. This method exists solely for debugging purposes, do not use in production.

Note

The Geocoding and Elevation are the two exceptions as they only have searchJson method available, the upstream API doesn't implement FlatBuffers.

var result = await GeocodingApi().requestJson(name: "London");
var result = await ElevationApi().requestJson(latitudes: [52.52], longitudes: [13.41]);

1.1.0 Migration Guide #

  • Every API now has Api suffix.
Weather() -> WeatherApi()
  • Except for enum variables, snake_case variables are changed to lowerCamelCase to follow Dart's standard linter rules.
Weather(temperature_unit: TemperatureUnit.celsius) -> WeatherApi(temperatureUnit: TemperatureUnit.celsius)
  • Hourly, Daily, Current enums are no longer available, instead, each API has their own set of enums:

    • WeatherHourly, WeatherDaily, WeatherCurrent enums for WeatherApi.
    • HistoricalHourly, HistoricalDaily enums for HistoricalApi.
    • And so on...
  • latitude, longitude, and some variables now moved to request methods, API classes only have some settings related to the formatting result:

// 1.1.0
var weather = Weather(
  latitude: 52.52,
  longitude: 13.41,
  temperature_unit: TemperatureUnit.celsius
);
var hourly = [Hourly.temperature_2m];
await weather.request(hourly: hourly);

// 2.0.0
final weather = WeatherApi(temperatureUnit: TemperatureUnit.celsius);
final response = await weather.request(
  latitude: 52.52,
  longitude: 13.41,
  hourly: {WeatherHourly.temperature_2m},
);

Bugs & Pull requests #

Before reporting an issue, please check Open-Meteo's docs to make sure you're calling the correct endpoint with the correct arguments. Contributions are welcome!

9
likes
160
pub points
69%
popularity

Publisher

verified publisherneurs.click

A simple, fast, asynchronous Dart/Flutter package for accessing the Open-Meteo API.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flat_buffers, http

More

Packages that depend on open_meteo