weath

Creator: coderz1093

Last updated:

Add to Cart

Description:

weather

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");
copied to clipboard
Alternatively, you can also specify a language for the weather reports such as Danish
WeatherFactory wf = new WeatherFactory("YOUR_API_KEY", language: Language.DANISH);
copied to clipboard
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);
copied to clipboard
Through geolocation:
Weather w = await wf.currentWeatherByLocation(lat, lon);
copied to clipboard
Through city name:
Weather w = await wf.currentWeatherByCityName(cityName);
copied to clipboard
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
copied to clipboard
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;
copied to clipboard
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);
copied to clipboard
Via city name
List<Weather> forecast = await wf.fiveDayForecastByCityName(cityName);
copied to clipboard
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.

NB: AndroidX support #
Only for Android API level 28
Update the contents of the android/gradle.properties file with the following:
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
copied to clipboard
Next, add the following dependencies to your android/build.gradle file:
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.2.0'
}
copied to clipboard
And finally, set the Android compile- and minimum SDK versions to compileSdkVersion 28, and minSdkVersion 21 respectively, inside the android/app/build.gradle file.
Languages #
The following languages are supported

AFRIKAANS
ALBANIAN
ARABIC
AZERBAIJANI
BULGARIAN
CATALAN
CZECH
DANISH
GERMAN
GREEK
ENGLISH
BASQUE
PERSIAN
FARSI
FINNISH
FRENCH
GALICIAN
HEBREW
HINDI
CROATIAN
HUNGARIAN
INDONESIAN
ITALIAN
JAPANESE
KOREAN
LATVIAN
LITHUANIAN
MACEDONIAN
NORWEGIAN
DUTCH
POLISH
PORTUGUESE
PORTUGUESE_BRAZIL
ROMANIAN
RUSSIAN
SWEDISH
SLOVAK
SLOVENIAN
SPANISH
SERBIAN
THAI
TURKISH
UKRAINIAN
VIETNAMESE
CHINESE_SIMPLIFIED
CHINESE_TRADITIONAL
ZULU

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.