Skip to main content

weather_open_meteo_client 1.0.0 copy "weather_open_meteo_client: ^1.0.0" to clipboard
weather_open_meteo_client: ^1.0.0 copied to clipboard

A Dart client for the free Open-Meteo weather API — current conditions, hourly and daily forecasts, and geocoding. No API key required.

weather_open_meteo_client #

A Dart client for the free Open-Meteo API: current conditions, hourly and daily forecasts, and geocoding. No API key required.

Pure Dart — works in Flutter apps, server-side Dart and CLI tools alike.

Install #

dependencies:
  weather_open_meteo_client: ^1.0.0

Usage #

By city name #

import 'package:weather_open_meteo_client/weather_open_meteo_client.dart';

final api = OpenMeteoApi();
final weather = await api.getWeatherByCityName('London');

print('${weather.current?.temperature2m}${weather.currentUnits?.temperature2m}');
api.close();

By coordinate #

Request exactly the variables you need — each one is an enum value, and the matching field on the response carries the same name:

final weather = await api.getWeatherByCoordinate(
  latitude: 51.5072,
  longitude: -0.1275,
  current: [CurrentParam.temperature2m, CurrentParam.weatherCode],
  hourly: [HourlyParam.temperature2m, HourlyParam.precipitationProbability],
  daily: [DailyParam.temperature2mMax, DailyParam.sunrise, DailyParam.sunset],
  forecastDays: 3,
);

print(weather.current?.temperature2m);          // 25.9
print(weather.hourly?.temperature2m?.first);    // 19.2
print(weather.daily?.sunrise?.first);           // DateTime

Anything you did not request stays null, and every series is aligned with the time series of the block it belongs to:

final hourly = weather.hourly!;
for (var i = 0; i < hourly.time.length; i++) {
  print('${hourly.time[i]}: ${hourly.temperature2m?[i]}');
}

Units and options #

await api.getWeatherByCoordinate(
  latitude: 51.5072,
  longitude: -0.1275,
  current: [CurrentParam.temperature2m],
  temperatureUnit: TemperatureUnit.fahrenheit,
  windSpeedUnit: WindSpeedUnit.mph,
  precipitationUnit: PrecipitationUnit.inch,
  timezone: Timezone.europeLondon,   // any IANA name; defaults to Timezone.auto
  pastDays: 2,
  startDate: DateTime(2026, 1, 1),   // or an explicit interval
  endDate: DateTime(2026, 1, 7),
);

Timestamps always arrive as DateTime, whether the API was asked for ISO8601 or TimeFormat.unixtime. Unix timestamps decode as UTC; ISO8601 ones decode as local wall time in the requested timezone.

Geocoding #

final places = await api.searchLocations('Springfield', count: 5);
for (final place in places) {
  print('${place.name}, ${place.admin1}, ${place.country} — ${place.population}');
}

final best = await api.findLocation('London');  // throws if nothing matches

Errors #

Every failure is an OpenMeteoException, carrying the reason reported by the API and the request that failed:

try {
  await api.getWeatherByCityName('nowhere at all');
} on LocationNotFoundFailure catch (e) {
  print(e.message);
} on OpenMeteoException catch (e) {
  print('${e.message} (${e.uri})');
}
Exception Thrown when
WeatherRequestFailure A forecast request failed or was rejected
WeatherResponseFailure A forecast response could not be parsed
LocationRequestFailure A geocoding request failed or was rejected
LocationNotFoundFailure No place matched the query

Lifetime #

OpenMeteoApi creates an http.Client unless you pass one. Reuse a single instance and close() it when done; a client you passed in is left for you to close.

final api = OpenMeteoApi(httpClient: myClient);  // shared, not closed by close()

Example #

See example/example.dart, runnable with:

dart run example/example.dart London

API documentation #

License #

MIT — see LICENSE.

13
likes
0
points
174
downloads

Publisher

verified publisherpetyaas.online

Weekly Downloads

A Dart client for the free Open-Meteo weather API — current conditions, hourly and daily forecasts, and geocoding. No API key required.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http, json_annotation

More

Packages that depend on weather_open_meteo_client