weather 3.2.1 
weather: ^3.2.1 copied to clipboard
A weather plugin for fetching current weather and forecasting via the OpenWeatherMap API. Works for both Android and iOS.
weather #
This package uses the OpenWeatherMAP API to get the current weather status as well as weather forecasts.
The weather can currently be fetched by providing a geolocation or a city name.
Install (Flutter) #
Add weather as a dependency in  pubspec.yaml.
For help on adding as a dependency, view the pubspec documenation.
Permissions #
No permissions are needed for this package in isolatation, however for getting the device's geolocation we recommend using the geolocator plugin.
Usage #
First and foremost you need an API key from OpenWeatherMap, which can be acquired for free here.
Next, an instance of a `WeatherFactory is created using the API key.
import 'package:weather/weather.dart';
...
WeatherFactory wf = new WeatherFactory("YOUR_API_KEY");
Alternatively, you can also specify a language for the weather reports such as Danish
WeatherFactory wf = new WeatherFactory("YOUR_API_KEY", language: Language.DANISH);
For all the supported languages, see the Languages section.
Current Weather #
For specific documentation on the current weather API, see the OpenWeatherMap weather API docs.
The current weather is queried either through a latitude and longitude or through a city name, i.e.
double lat = 55.0111;
double lon = 15.0569;
String key = '856822fd8e22db5e1ba48c0e7d69844a';
String cityName = 'Kongens Lyngby';
WeatherFactory wf = WeatherFactory(key);
Through geolocation:
Weather w = await wf.currentWeatherByLocation(lat, lon);
Through city name:
Weather w = await wf.currentWeatherByCityName(cityName);
Example output:
Place Name: Kongens Lyngby [DK] (55.77, 12.5)
Date: 2020-07-13 17:17:34.000
Weather: Clouds, broken clouds
Temp: 17.1 Celsius, Temp (min): 16.7 Celsius, Temp (max): 18.0 Celsius,  Temp (feels like): 13.4 Celsius
Sunrise: 2020-07-13 04:43:53.000, Sunset: 2020-07-13 21:47:15.000
Weather Condition code: 803
For a complete list of all the properties of the Weather class, check the documentation
Temperature unit
The Temperature class holds a temperature and can output the temperature in the following units:
- Celsius
 - Fahrenheit
 - Kelvin
 
This can be done as given a Weather object w
double celsius = w.temperature.celsius;
double fahrenheit = w.temperature.fahrenheit;
double kelvin = w.temperature.kelvin;
Five-day Weather Forecast #
For API documentation on the forecast API, see the OpenWeatherMap forecast API docs.
The forecast is a 5-day prediction and contains a list of Weather objects with 3 hours between them.
The forecast can also be fetched via geolocation or city name.
Via geolocation
List<Weather> forecast = await wf.fiveDayForecastByLocation(lat, lon);
Via city name
List<Weather> forecast = await wf.fiveDayForecastByCityName(cityName);
Exceptions #
The following are cases for which an exception will be thrown:
- The provided OpenWeather API key is invalid
 - An bad response was given by the API; it may be down.
 
Languages #
The following languages are supported
AFRIKAANSALBANIANARABICAZERBAIJANIBULGARIANCATALANCZECHDANISHGERMANGREEKENGLISHBASQUEPERSIANFARSIFINNISHFRENCHGALICIANHEBREWHINDICROATIANHUNGARIANINDONESIANITALIANJAPANESEKOREANLATVIANLITHUANIANMACEDONIANNORWEGIANDUTCHPOLISHPORTUGUESEPORTUGUESE_BRAZILROMANIANRUSSIANSWEDISHSLOVAKSLOVENIANSPANISHSERBIANTHAITURKISHUKRAINIANVIETNAMESECHINESE_SIMPLIFIEDCHINESE_TRADITIONALZULU