weather 0.9.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 92

weather #

This package uses the OpenWeatherMAP API to get the current weather status as well as weather forecasts.

pub package

Install (Flutter) #

Add weather as a dependency in pubspec.yaml. For help on adding as a dependency, view the pubspec documenation.

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

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'
} 

And finally, set the Android compile- and minimum SDK versions to compileSdkVersion 28, and minSdkVersion 21 respectively, inside the android/app/build.gradle file.

Permissions #

The package uses your location to fetch weather data, therefore location tracking must be enabled.

Android #

Add the following entry to your manifest.xml file, in the Android project of your application:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

In addition, it is recommended to set your minimum SDK version to 21.

iOS #

  1. Open the XCode project of your app, named Runner.xcodeproj
  2. Locate the info.plist file in the Runner directory.
  3. Right click info.plist and choose Open as > Source Code.
  4. Add the following entries inside the <dict></dict> tags`:
<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>

Known issues #

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

Usage #

First and foremost you need an API key from OpenWeatherMap, which can be acquired for free here.

import 'package:weather/weather.dart';

...

WeatherStation weatherStation = new WeatherStation("YOUR_API_KEY");

Query current weather #

For specific documentation on the current weather API, see the OpenWeatherMap weather API docs.

Weather weather = await weatherStation.currentWeather();

For a complete list of all the properties of the Weather class, check the documentation

Get 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.fiveDayForecast();

Exceptions #

The following are cases for which an exception will be thrown:

  • No Location permission was given
  • The provided OpenWeather API key is invalid
  • An bad response was given by the API; it may be down.

0.9.5 #

  • better handling of requesting location permissions

0.9.4 #

  • Updated the README

0.9.3 #

  • Refactored how a http response is sent and parsed.
  • Added exceptions for bad HTTP responses.
  • Renamed existing exception classes to something more meaningful.

0.9.2 #

  • Added support for Android X
  • This version will not work for Android, unless instructions are followed carefully.

0.1.3 #

  • Weather plugin works for Android and iOS
  • Plugin now use objects to store weather information, rather than JSON

example/README.md

weather_example #

Demonstrates how to use the weather plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  weather: ^0.9.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:weather/weather.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
84
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Dec 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.2

Health suggestions

Format lib/weather.dart.

Run flutter format to format lib/weather.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
http ^0.12.0 0.12.0+2
location ^2.3.3 2.3.5
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
http_parser 3.1.3
meta 1.1.8
path 1.6.4
pedantic 1.9.0
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
test ^1.6.1