This package uses the OpenWeatherMAP API to get the current weather status as well as weather forecasts.
weather as a dependency in
For help on adding as a dependency, view the pubspec documenation.
The package uses your location to fetch weather data, therefore location tracking must be enabled.
Add the following entry to your
manifest.xml file, in the Android project of your application:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
In addition, it is recommended to set your minimum SDK version to 21.
- Open the XCode project of your app, named
- Locate the
info.plistfile in the
- Right click
Open as > Source Code.
- Add the following entries inside the
<key>NSLocationWhenInUseUsageDescription</key> <string>This app uses location to forecast the weather.</string> <key>NSLocationAlwaysUsageDescription</key> <string>This app uses location to forecast the weather.</string>
There is an issue with the
location plugin which this package depends on, where an error with the following message
The use of Swift 3 @objc inference in Swift 4 mode is deprecated
may be thrown. For a solution, check the following stack overflow question: https://stackoverflow.com/questions/44379348/the-use-of-swift-3-objc-inference-in-swift-4-mode-is-deprecated
First and foremost you need an API key from OpenWeatherMap, which can be acquired for free here.
WeatherStation weatherStation = new WeatherStation("YOUR_API_KEY");
Query current weather
For api documentation on the current weather API, see the OpenWeatherMap weather API docs.
Weather weather = await weatherStation.getCurrentWeather();
Get current temperature
The Temperature class holds a temperature and can output the temperature in Celsius, Fahrenheit, and Kelvin:
double celsius = weather.temperature.celsius; double fahrenheit = weather.temperature.celsius; double kelvin = weather.temperature.kelvin;
Query 5 day forecast
For API documentation on the forecast API, see the OpenWeatherMap forecast API docs.
List<Weather> forecasts = await weatherStation.getFiveDayForecast();
- Built-in types and core primitives for a Flutter application. [...]
- Support for asynchronous programming, with classes such as Future and Stream. [...]
- Classes and utilities that supplement the collection support in dart:core. [...]
- Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
- Built-in types, collections, and other core functionality for every Dart program. [...]
- Interact with developer tools such as the debugger and inspector. [...]
- Mathematical constants and functions, plus a random number generator. [...]
- Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]
- File, socket, HTTP, and other I/O support for non-web applications. [...]
- Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]